SPEC-2513 Fixes to enable w4459 (#1107)

* fixing w4459

* Fixes for nounity

* putting OLD_APARAM_USER in a common place to avoid duplicated declarations
This commit is contained in:
Esteban Papp
2021-06-03 11:12:54 -07:00
committed by GitHub
parent ba02652e63
commit 5d7aae9bd8
21 changed files with 68 additions and 85 deletions
@@ -27,6 +27,6 @@ namespace NumericalMethods::Optimization
const double epsilon = 1e-7;
// values recommended in Nocedal and Wright for constants in the Wolfe conditions for satisfactory solution improvement
const double c1 = 1e-4;
const double c2 = 0.9;
const double WolfeConditionsC1 = 1e-4;
const double WolfeConditionsC2 = 0.9;
} // namespace NumericalMethods::Optimization
@@ -162,16 +162,16 @@ namespace NumericalMethods::Optimization
{
// if the value of f corresponding to alpha1 isn't sufficiently small compared to f at x0,
// then the interval [alpha0 ... alpha1] must bracket a suitable point.
if ((f_alpha1 > f_x0 + c1 * alpha1 * df_x0) || (iteration > 0 && f_alpha1 > f_alpha0))
if ((f_alpha1 > f_x0 + WolfeConditionsC1 * alpha1 * df_x0) || (iteration > 0 && f_alpha1 > f_alpha0))
{
return SelectStepSizeFromInterval(alpha0, alpha1, f_alpha0, f_alpha1, df_alpha0,
f, x0, searchDirection, f_x0, df_x0, c1, c2);
f, x0, searchDirection, f_x0, df_x0, WolfeConditionsC1, WolfeConditionsC2);
}
// otherwise, if the derivative corresponding to alpha1 is large enough, alpha1 already
// satisfies the Wolfe conditions and so return alpha1.
double df_alpha1 = DirectionalDerivative(f, x0 + alpha1 * searchDirection, searchDirection);
if (fabs(df_alpha1) <= -c2 * df_x0)
if (fabs(df_alpha1) <= -WolfeConditionsC2 * df_x0)
{
LineSearchResult result;
result.m_outcome = LineSearchOutcome::Success;
@@ -184,7 +184,7 @@ namespace NumericalMethods::Optimization
if (df_alpha1 >= 0.0)
{
return SelectStepSizeFromInterval(alpha1, alpha0, f_alpha1, f_alpha0, df_alpha1,
f, x0, searchDirection, f_x0, df_x0, c1, c2);
f, x0, searchDirection, f_x0, df_x0, WolfeConditionsC1, WolfeConditionsC2);
}
// haven't found an interval which is guaranteed to bracket a suitable point,
@@ -158,12 +158,12 @@ namespace NumericalMethods::Optimization
double f_x0 = f_alpha0;
double df_x0 = df_alpha0;
LineSearchResult lineSearchResult = SelectStepSizeFromInterval(alpha0, alpha1, f_alpha0, f_alpha1, df_alpha0,
testFunctionRosenbrock, x0, searchDirection, f_x0, df_x0, c1, c2);
testFunctionRosenbrock, x0, searchDirection, f_x0, df_x0, WolfeConditionsC1, WolfeConditionsC2);
EXPECT_TRUE(lineSearchResult.m_outcome == LineSearchOutcome::Success);
// check that the Wolfe conditions are satisfied by the returned step size
EXPECT_TRUE(lineSearchResult.m_functionValue < f_x0 + c1 * df_x0 * lineSearchResult.m_stepSize);
EXPECT_TRUE(fabs(lineSearchResult.m_derivativeValue) <= -c2 * df_x0);
EXPECT_TRUE(lineSearchResult.m_functionValue < f_x0 + WolfeConditionsC1 * df_x0 * lineSearchResult.m_stepSize);
EXPECT_TRUE(fabs(lineSearchResult.m_derivativeValue) <= -WolfeConditionsC2 * df_x0);
}
TEST(OptimizationTest, LineSearch_VariousSearchDirections_SatisfiesWolfeCondition)
@@ -180,8 +180,8 @@ namespace NumericalMethods::Optimization
EXPECT_TRUE(lineSearchResult.m_outcome == LineSearchOutcome::Success);
// check that the Wolfe conditions are satisfied by the returned step size
EXPECT_TRUE(lineSearchResult.m_functionValue < f_x0 + c1 * df_x0 * lineSearchResult.m_stepSize);
EXPECT_TRUE(fabs(lineSearchResult.m_derivativeValue) <= -c2 * df_x0);
EXPECT_TRUE(lineSearchResult.m_functionValue < f_x0 + WolfeConditionsC1 * df_x0 * lineSearchResult.m_stepSize);
EXPECT_TRUE(fabs(lineSearchResult.m_derivativeValue) <= -WolfeConditionsC2 * df_x0);
}
}