Loading...
Searching...
No Matches
MapPriorBarrier.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// Copyright (c) gpridge developers
3// See LICENSE for details.
4
5#ifndef GPR_ML_MAP_PRIOR_BARRIER_H_
6#define GPR_ML_MAP_PRIOR_BARRIER_H_
7
8#include <cmath>
9#include <limits>
10
11namespace funcmin {
12namespace detail {
13
14inline bool isLogBarrierInterior(double gap) noexcept
15{
16 return std::isfinite(gap) && gap > 0.0;
17}
18
19inline bool addLogBarrierPenalty(double gap, double gap_derivative,
20 double strength, double& energy,
21 double* gradient_component)
22{
23 if (!isLogBarrierInterior(gap) || !std::isfinite(gap_derivative) ||
24 !std::isfinite(strength))
25 return false;
26 energy -= strength * std::log(gap);
27 if (gradient_component != nullptr) {
28 *gradient_component -= strength * gap_derivative / gap;
29 return std::isfinite(*gradient_component);
30 }
31 return std::isfinite(energy);
32}
33
34inline double logBarrierDirectionalCurvature(double gap,
35 double gap_directional_derivative,
36 double strength)
37{
38 if (!isLogBarrierInterior(gap) ||
39 !std::isfinite(gap_directional_derivative) ||
40 !std::isfinite(strength)) {
41 return std::numeric_limits<double>::infinity();
42 }
43 return strength * gap_directional_derivative * gap_directional_derivative /
44 (gap * gap);
45}
46
47} // namespace detail
48} // namespace funcmin
49
50#endif // GPR_ML_MAP_PRIOR_BARRIER_H_