From ce08ba94394d00bfb2312aecea53b0b114a6f2a9 Mon Sep 17 00:00:00 2001 From: Trevor Blackwell Date: Sat, 13 Aug 2022 12:01:01 -0700 Subject: [PATCH 1/2] Avoid alphaStar = -inf when du contains a zero When du(i) = 0 and it's approaching a lower bound, FindAlpha can return -inf. It should only return values in [0,1]. The added check fixes it --- include/cppoptlib/solver/lbfgsb.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/cppoptlib/solver/lbfgsb.h b/include/cppoptlib/solver/lbfgsb.h index c0253f7..b46cc67 100644 --- a/include/cppoptlib/solver/lbfgsb.h +++ b/include/cppoptlib/solver/lbfgsb.h @@ -242,13 +242,14 @@ class Lbfgsb : public Solver { alphastar, (upper_bound_(free_variables.at(i)) - x_cp(free_variables.at(i))) / du(i)); - } else { + } else if (du(i) < 0) { alphastar = std::min( alphastar, (lower_bound_(free_variables.at(i)) - x_cp(free_variables.at(i))) / du(i)); } } + assert(alphastar >= 0); return alphastar; } From dfd85a4fc3501e010d84ba39c5745a235d6e544a Mon Sep 17 00:00:00 2001 From: Trevor Blackwell Date: Sat, 13 Aug 2022 12:13:49 -0700 Subject: [PATCH 2/2] Fix alphaStar=-inf --- include/cppoptlib/solver/lbfgsb.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/cppoptlib/solver/lbfgsb.h b/include/cppoptlib/solver/lbfgsb.h index c0253f7..963a9de 100644 --- a/include/cppoptlib/solver/lbfgsb.h +++ b/include/cppoptlib/solver/lbfgsb.h @@ -242,13 +242,15 @@ class Lbfgsb : public Solver { alphastar, (upper_bound_(free_variables.at(i)) - x_cp(free_variables.at(i))) / du(i)); - } else { + } + else if (du(i) < 0) { alphastar = std::min( alphastar, (lower_bound_(free_variables.at(i)) - x_cp(free_variables.at(i))) / du(i)); } } + assert(alphastar >= 0); return alphastar; }