Loading...
Searching...
No Matches
funcmin::RgminOpt Class Reference

#include <gpr/ml/RgminOpt.h>

Public Member Functions

void setAlgorithmSettings (const gpr::ScgOptimizationSettings &s)
void setMethod (rgmin::Method m) noexcept
void setMethod (rgmin_method_t m) noexcept
rgmin::Method getMethod () const noexcept
void setMemory (std::size_t m) noexcept
std::size_t lbfgsPairCap () const noexcept
std::size_t appliedLbfgsMemoryForTesting () const noexcept
void setMaxMove (double m) noexcept
void setGradTol (double g) noexcept
void setBox (Eigen::VectorXd lower, Eigen::VectorXd upper)
 Coordinate box on x + p. Empty is unbounded on that side.
void setPersistentSession (bool keep) noexcept
void setInitialLogMove (double distance) noexcept
void setInitialLogMoveWholeSession (bool whole_session) noexcept
void forgetSession () noexcept
 Drop the retained memory: the next fit starts cold.
std::size_t warmStarts () const noexcept
std::size_t warmPairs () const noexcept
std::size_t logicalObjectiveWork () const noexcept
 Objective-count units for the fit under a single-entry request cache.
std::size_t physicalObjectiveWork () const noexcept
 Executed objective-count units, including final holder restoration.
template<typename ClassName, typename FuncName>
void optimize (const gpr::EigenMatrix &x, const Eigen::VectorXd &x_ind, const Eigen::VectorXd &y, Eigen::VectorXd &w, FuncName func_to_min, ClassName &holder, double, const Eigen::VectorXd &lengthscale_rho0=Eigen::VectorXd(), const MapObjectiveConfig *objective_config=nullptr)
template<typename ClassName, typename FuncName>
void optimizeWithObjectiveValues (const gpr::EigenMatrix &x, const Eigen::VectorXd &x_ind, const Eigen::VectorXd &y, Eigen::VectorXd &w, FuncName func_to_min, ClassName &holder, double barrier_strength, const Eigen::VectorXd &lengthscale_rho0, const MapObjectiveConfig *objective_config, double *opening_value_out, double *last_value_out)

Static Public Member Functions

static bool methodFromName (const char *name, rgmin_method_t &out) noexcept

Public Attributes

bool failedOptim = false
bool exhaustedIterationBudget = false
int completedIterations = 0

Detailed Description

Gradient-only rgmin session on the MAP objective. The solver axis is rgmin::optimize::Method. MAP_LBFGS selects L-BFGS. The C ABI is the hourglass; this class drives the RAII wrap. RgminScg stays separate: rgmin_minimize_scg takes SCG parameters and a curvature callback the generic entry does not carry.

Newton and RFO need an analytic Hessian of the marginal likelihood, which this objective does not supply.

Definition at line 38 of file RgminOpt.h.

Member Function Documentation

◆ appliedLbfgsMemoryForTesting()

std::size_t funcmin::RgminOpt::appliedLbfgsMemoryForTesting ( ) const
inlinenodiscardnoexcept

Pair cap installed on the session of the last fit. Zero before that fit.

Definition at line 122 of file RgminOpt.h.

123 {
124 return session_memory;
125 }

◆ forgetSession()

void funcmin::RgminOpt::forgetSession ( )
inlinenoexcept

Drop the retained memory: the next fit starts cold.

Definition at line 182 of file RgminOpt.h.

183 {
184 session.reset();
185 retained_s.clear();
186 retained_y.clear();
187 }

◆ getMethod()

rgmin::Method funcmin::RgminOpt::getMethod ( ) const
inlinenodiscardnoexcept

Definition at line 57 of file RgminOpt.h.

58 {
59 return method;
60 }

◆ lbfgsPairCap()

std::size_t funcmin::RgminOpt::lbfgsPairCap ( ) const
inlinenodiscardnoexcept

Definition at line 116 of file RgminOpt.h.

117 {
118 return memory > 0 ? memory : rgmin::OptimizeControl{}.memory;
119 }

◆ logicalObjectiveWork()

std::size_t funcmin::RgminOpt::logicalObjectiveWork ( ) const
inlinenodiscardnoexcept

Objective-count units for the fit under a single-entry request cache.

Definition at line 204 of file RgminOpt.h.

205 {
206 return logical_objective_work;
207 }

◆ methodFromName()

bool funcmin::RgminOpt::methodFromName ( const char * name,
rgmin_method_t & out )
inlinestaticnodiscardnoexcept

Map a rgmin:<method> spelling onto the solver enum.

Newton and RFO are absent on purpose: both need an analytic Hessian of the marginal likelihood, which the MAP objective does not supply. Accepting their names here would build a session that cannot take a step.

Definition at line 68 of file RgminOpt.h.

70 {
71 if (name == nullptr) return false;
72 const std::string_view n{name};
73 struct Entry {
74 std::string_view name;
75 rgmin_method_t method;
76 };
77 static constexpr Entry table[] = {
78 {"lbfgs", RGMIN_LBFGS},
79 {"bfgs", RGMIN_BFGS},
80 {"sr1", RGMIN_SR1},
81 {"sr2", RGMIN_SR2},
82 {"steepest", RGMIN_STEEPEST},
83 {"adam", RGMIN_ADAM},
84 {"bb", RGMIN_BB},
85 {"fire", RGMIN_FIRE},
86 {"fire2", RGMIN_FIRE2},
87 {"dogleg", RGMIN_DOGLEG},
88 {"pso", RGMIN_PSO},
89 // Nonlinear conjugate gradient rules.
90 {"polak-ribiere", RGMIN_POLAK_RIBIERE},
91 {"fletcher-reeves", RGMIN_FLETCHER_REEVES},
92 {"hestenes-stiefel", RGMIN_HESTENES_STIEFEL},
93 {"dai-yuan", RGMIN_DAI_YUAN},
94 {"conjugate-descent", RGMIN_CONJUGATE_DESCENT},
95 {"hager-zhang", RGMIN_HAGER_ZHANG},
96 {"liu-storey", RGMIN_LIU_STOREY},
97 {"fr-pr", RGMIN_FR_PR},
98 };
99 for (const auto& e: table) {
100 if (e.name == n) {
101 out = e.method;
102 return true;
103 }
104 }
105 return false;
106 }
eon_relax_band_t eon_relax_surface_fn void eon_relax_outcome_t * out

◆ optimize()

template<typename ClassName, typename FuncName>
void funcmin::RgminOpt::optimize ( const gpr::EigenMatrix & x,
const Eigen::VectorXd & x_ind,
const Eigen::VectorXd & y,
Eigen::VectorXd & w,
FuncName func_to_min,
ClassName & holder,
double current_barrier_strength,
const Eigen::VectorXd & lengthscale_rho0 = Eigen::VectorXd(),
const MapObjectiveConfig * objective_config = nullptr )

Definition at line 19 of file RgminOpt.inl.

25{
26 optimizeImpl(x, x_ind, y, w, func_to_min, holder, current_barrier_strength,
27 lengthscale_rho0, objective_config, nullptr, nullptr);
28}
@ x
Definition Enums.h:28
@ y
Definition Enums.h:28

◆ optimizeWithObjectiveValues()

template<typename ClassName, typename FuncName>
void funcmin::RgminOpt::optimizeWithObjectiveValues ( const gpr::EigenMatrix & x,
const Eigen::VectorXd & x_ind,
const Eigen::VectorXd & y,
Eigen::VectorXd & w,
FuncName func_to_min,
ClassName & holder,
double barrier_strength,
const Eigen::VectorXd & lengthscale_rho0,
const MapObjectiveConfig * objective_config,
double * opening_value_out,
double * last_value_out )

Definition at line 31 of file RgminOpt.inl.

38{
39 optimizeImpl(x, x_ind, y, w, func_to_min, holder, current_barrier_strength,
40 lengthscale_rho0, objective_config, opening_value_out,
41 last_value_out);
42}

◆ physicalObjectiveWork()

std::size_t funcmin::RgminOpt::physicalObjectiveWork ( ) const
inlinenodiscardnoexcept

Executed objective-count units, including final holder restoration.

Definition at line 209 of file RgminOpt.h.

210 {
211 return physical_objective_work;
212 }

◆ setAlgorithmSettings()

void funcmin::RgminOpt::setAlgorithmSettings ( const gpr::ScgOptimizationSettings & s)
inline

Definition at line 44 of file RgminOpt.h.

45 {
46 settings = s;
47 }

◆ setBox()

void funcmin::RgminOpt::setBox ( Eigen::VectorXd lower,
Eigen::VectorXd upper )
inline

Coordinate box on x + p. Empty is unbounded on that side.

Definition at line 136 of file RgminOpt.h.

137 {
138 box_lo = std::move(lower);
139 box_hi = std::move(upper);
140 }

◆ setGradTol()

void funcmin::RgminOpt::setGradTol ( double g)
inlinenoexcept

Definition at line 130 of file RgminOpt.h.

131 {
132 gtol = g;
133 }

◆ setInitialLogMove()

void funcmin::RgminOpt::setInitialLogMove ( double distance)
inlinenoexcept

Largest distance the first step of a cold session may move the parameters. Hyperparameters live in log coordinates, so one unit is a factor e in a length scale or an amplitude, and the objective is only meaningful near the start. The opening step of the session is not the unit step along the negative gradient when the gradient is large: the first step is capped through the solver's Euclidean move cap, which the line searches and trust radii honour, and the caller's cap is restored after it. Zero leaves the first step to the solver.

Definition at line 167 of file RgminOpt.h.

168 {
169 initial_log_move = distance;
170 }

◆ setInitialLogMoveWholeSession()

void funcmin::RgminOpt::setInitialLogMoveWholeSession ( bool whole_session)
inlinenoexcept

How the bound is applied. True (default): the opening step of the session control is lowered so the first trial of a cold session moves at most the bound, set from the gradient norm at the cold start, and it stays lowered for the life of the session, so every line search of the session opens there. False: only the first step of a cold session is capped, through the solver's move cap.

Definition at line 177 of file RgminOpt.h.

178 {
179 initial_log_move_whole_session = whole_session;
180 }

◆ setMaxMove()

void funcmin::RgminOpt::setMaxMove ( double m)
inlinenoexcept

Definition at line 126 of file RgminOpt.h.

127 {
128 maxmove = m;
129 }

◆ setMemory()

void funcmin::RgminOpt::setMemory ( std::size_t m)
inlinenoexcept

L-BFGS pairs kept by the solver and by the warm-start record. Zero selects the cap rgmin publishes as the default of OptimizeControl::memory, which is also the cap the C ABI uses when a control's memory is 0.

Definition at line 112 of file RgminOpt.h.

113 {
114 memory = m;
115 }

◆ setMethod() [1/2]

void funcmin::RgminOpt::setMethod ( rgmin::Method m)
inlinenoexcept

Definition at line 49 of file RgminOpt.h.

50 {
51 method = m;
52 }

◆ setMethod() [2/2]

void funcmin::RgminOpt::setMethod ( rgmin_method_t m)
inlinenoexcept

Definition at line 53 of file RgminOpt.h.

54 {
55 method = static_cast<rgmin::Method>(m);
56 }

◆ setPersistentSession()

void funcmin::RgminOpt::setPersistentSession ( bool keep)
inlinenoexcept

Transplant the previous fit's record into the next fit (off by default: every fit then opens a fresh session at the previous optimum with the cold opening step). A sequence of marginal likelihood fits, one per acquisition, minimises objectives that differ by the rows added since the last: the accepted steps of the previous fit, as curvature pairs, still describe the curvature at its optimum. Every fit opens a fresh session (its opening step is scaled to the new gradient); a warm start transplants the pairs into it when the record describes this objective (see warmPairs), and a caller that has found measured rows contradicting the posterior drops the record first (forgetSession). A changed dimension, method, tolerance, step cap or active subspace starts cold, and so does the fit after one that did not converge.

Definition at line 154 of file RgminOpt.h.

155 {
156 persistent_session = keep;
157 }

◆ warmPairs()

std::size_t funcmin::RgminOpt::warmPairs ( ) const
inlinenodiscardnoexcept

Curvature pairs the last fit took from the previous fit's record: zero when the record was dropped as another objective's (the move it proposes for the new gradient exceeds the opening trust, or the decrease it claims exceeds one nat per parameter).

Definition at line 198 of file RgminOpt.h.

199 {
200 return last_warm_pairs;
201 }

◆ warmStarts()

std::size_t funcmin::RgminOpt::warmStarts ( ) const
inlinenodiscardnoexcept

Fits that opened after a converged fit of a compatible session (the previous optimum as start; the record consulted when transplanting).

Definition at line 190 of file RgminOpt.h.

191 {
192 return warm_starts;
193 }

Member Data Documentation

◆ completedIterations

int funcmin::RgminOpt::completedIterations = 0

Definition at line 42 of file RgminOpt.h.

◆ exhaustedIterationBudget

bool funcmin::RgminOpt::exhaustedIterationBudget = false

Definition at line 41 of file RgminOpt.h.

◆ failedOptim

bool funcmin::RgminOpt::failedOptim = false

Definition at line 40 of file RgminOpt.h.


The documentation for this class was generated from the following files: