optimize.Bounds - does lb need to be less than ub?
Hi all, in https://github.com/scipy/scipy/pull/18483 `Bounds` is being modified slightly. Currently there's a check in there: ``` if (self.lb > self.ub).any(): raise ValueError("An upper bound is less than the corresponding lower bound.") ``` I would personally find it useful if Bounds was more robust in this area, and was able to deal with lb entries that were greater than the ub. I would like Bounds to have a clear up code with something like: ``` _lb = np.minimum(self.lb, self.ub) _ub = np.maximum(self.lb, self.ub) self.lb = _lb self.ub = _ub ``` What are peoples thoughts on this? A. _____________________________________ Dr. Andrew Nelson _____________________________________
My first thought is that if the bounds are flipped, in the majority of cases it is a bug, and erroring out is the correct action. What kind of scenario do you have? And can't you apply the fix to the boundaries before the function? /David On Thu, 18 May 2023, 18:41 Andrew Nelson, <andyfaff@gmail.com> wrote:
Hi all, in https://github.com/scipy/scipy/pull/18483 `Bounds` is being modified slightly.
Currently there's a check in there:
``` if (self.lb > self.ub).any(): raise ValueError("An upper bound is less than the corresponding lower bound.") ```
I would personally find it useful if Bounds was more robust in this area, and was able to deal with lb entries that were greater than the ub. I would like Bounds to have a clear up code with something like:
``` _lb = np.minimum(self.lb, self.ub) _ub = np.maximum(self.lb, self.ub) self.lb = _lb self.ub = _ub ```
What are peoples thoughts on this?
A.
_____________________________________ Dr. Andrew Nelson
_____________________________________ _______________________________________________ SciPy-Dev mailing list -- scipy-dev@python.org To unsubscribe send an email to scipy-dev-leave@python.org https://mail.python.org/mailman3/lists/scipy-dev.python.org/ Member address: davidmenhur@gmail.com
On 5/18/23, David Menéndez Hurtado <davidmenhur@gmail.com> wrote:
My first thought is that if the bounds are flipped, in the majority of cases it is a bug, and erroring out is the correct action.
What kind of scenario do you have? And can't you apply the fix to the boundaries before the function?
/David
On Thu, 18 May 2023, 18:41 Andrew Nelson, <andyfaff@gmail.com> wrote:
Hi all, in https://github.com/scipy/scipy/pull/18483 `Bounds` is being modified slightly.
Currently there's a check in there:
``` if (self.lb > self.ub).any(): raise ValueError("An upper bound is less than the corresponding lower bound.") ```
I would personally find it useful if Bounds was more robust in this area, and was able to deal with lb entries that were greater than the ub. I would like Bounds to have a clear up code with something like:
``` _lb = np.minimum(self.lb, self.ub) _ub = np.maximum(self.lb, self.ub) self.lb = _lb self.ub = _ub ```
What are peoples thoughts on this?
My first thought is the same as David's: this sounds like it will hide bugs. `lb` and `ub` clearly stand for "lower bound" and "upper bound", and having our code guess that the user wants them reversed if `lb` > `ub` seems like a bad idea. Warren
A.
_____________________________________ Dr. Andrew Nelson
_____________________________________ _______________________________________________ SciPy-Dev mailing list -- scipy-dev@python.org To unsubscribe send an email to scipy-dev-leave@python.org https://mail.python.org/mailman3/lists/scipy-dev.python.org/ Member address: davidmenhur@gmail.com
In the spirit of explicit is better then implicit, I think the current behavior is desirable. It may catch problems that are I'll posed or otherwise codes wrong. Kevin On Thu, May 18, 2023, 17:41 Andrew Nelson <andyfaff@gmail.com> wrote:
Hi all, in https://github.com/scipy/scipy/pull/18483 `Bounds` is being modified slightly.
Currently there's a check in there:
``` if (self.lb > self.ub).any(): raise ValueError("An upper bound is less than the corresponding lower bound.") ```
I would personally find it useful if Bounds was more robust in this area, and was able to deal with lb entries that were greater than the ub. I would like Bounds to have a clear up code with something like:
``` _lb = np.minimum(self.lb, self.ub) _ub = np.maximum(self.lb, self.ub) self.lb = _lb self.ub = _ub ```
What are peoples thoughts on this?
A.
_____________________________________ Dr. Andrew Nelson
_____________________________________ _______________________________________________ SciPy-Dev mailing list -- scipy-dev@python.org To unsubscribe send an email to scipy-dev-leave@python.org https://mail.python.org/mailman3/lists/scipy-dev.python.org/ Member address: kevin.k.sheppard@gmail.com
participants (4)
-
Andrew Nelson -
David Menéndez Hurtado -
Kevin Sheppard -
Warren Weckesser