Loading...
Searching...
No Matches
funcmin::RgminNlmlCtx< ClassName, FuncName > Struct Template Reference

#include <gpr/ml/RgminObjective.h>

Classes

struct  Sample

Public Member Functions

 RgminNlmlCtx (const gpr::EigenMatrix &positions, const Eigen::VectorXd &indices, const Eigen::VectorXd &targets, ClassName &model, FuncName objective, const MapObjectiveConfig &configuration, bool use_exact_curvature, bool retain_step_samples=false, std::function< bool()> stop_requested={})
rgmin_status_t captureCallbackError (const char *callback) noexcept
void pinAt (const Eigen::VectorXd &w)
std::size_t logicalObjectiveWork () const noexcept
std::size_t physicalObjectiveWork () const noexcept
const Sample & evalAt (const Eigen::VectorXd &w)
rgmin_status_t restoreHolderAt (const Eigen::VectorXd &w) noexcept

Public Attributes

const gpr::EigenMatrix & x
const Eigen::VectorXd & x_ind
const Eigen::VectorXd & y
ClassName & holder
const FuncName func
const MapObjectiveConfig & map_cfg
const bool exact_curvature
bool trace_evaluations = false
bool hessian_vector_fallback = false
RgminCallbackFailure failure

Detailed Description

template<typename ClassName, typename FuncName>
struct funcmin::RgminNlmlCtx< ClassName, FuncName >

Synchronous objective view shared by the SCG and gradient-only adapters. Input arrays, the model and the member function remain valid for the whole minimize/step call. Model mutation belongs to the objective; coordinate publication belongs to the optimizer adapter after callback success.

Definition at line 80 of file RgminObjective.h.

Constructor & Destructor Documentation

◆ RgminNlmlCtx()

template<typename ClassName, typename FuncName>
funcmin::RgminNlmlCtx< ClassName, FuncName >::RgminNlmlCtx ( const gpr::EigenMatrix & positions,
const Eigen::VectorXd & indices,
const Eigen::VectorXd & targets,
ClassName & model,
FuncName objective,
const MapObjectiveConfig & configuration,
bool use_exact_curvature,
bool retain_step_samples = false,
std::function< bool()> stop_requested = {} )
inline

Definition at line 108 of file RgminObjective.h.

113 {})
114 : x(positions),
115 x_ind(indices),
116 y(targets),
117 holder(model),
121 retain_samples_(retain_step_samples && !use_exact_curvature),
122 seed_retained_(retain_samples_),
123 stop_requested_(std::move(stop_requested))
124 {
125 if (func == nullptr)
126 throw std::invalid_argument("rgmin requires an objective function");
127 if constexpr (holder_caches_samples_) {
128 if (retain_samples_) {
129 if (const auto* point = holder.cachedObjectiveParameters()) {
130 holder_request_w_ = *point;
131 holder_request_ok_ = point->allFinite();
132 }
133 }
134 }
135 }
const Eigen::VectorXd & x_ind
const MapObjectiveConfig & map_cfg
const gpr::EigenMatrix & x
const Eigen::VectorXd & y

Member Function Documentation

◆ captureCallbackError()

template<typename ClassName, typename FuncName>
rgmin_status_t funcmin::RgminNlmlCtx< ClassName, FuncName >::captureCallbackError ( const char * callback)
inlinenoexcept

Definition at line 137 of file RgminObjective.h.

138 {
139 trial_.valid = false;
140 retained_.valid = false;
141 request_ok_ = false;
142 holder_request_ok_ = false;
143 physical_ok_ = false;
144 seed_retained_ = false;
145 return failure.capture(callback);
146 }
RgminCallbackFailure failure

◆ evalAt()

template<typename ClassName, typename FuncName>
const Sample & funcmin::RgminNlmlCtx< ClassName, FuncName >::evalAt ( const Eigen::VectorXd & w)
inline

Definition at line 170 of file RgminObjective.h.

171 {
172 if (stop_requested_ && stop_requested_())
174 // The budget follows a separate single-entry request cache, including
175 // rejected-domain keys and numerical equality of the signs of zero.
176 const bool logical_miss =
177 retain_samples_ &&
178 (!request_ok_ || !sameRequestPoint(request_w_, w));
179 if (logical_miss) {
180 request_ok_ = false;
181 request_w_ = w;
182 }
184 if constexpr (holder_caches_samples_) {
185 if (holder_request_ok_ && sameRequestPoint(holder_request_w_, w))
186 charge_work = false;
187 }
188 const Sample* sample = nullptr;
189 if (trial_.valid && (retain_samples_ ? sameRepresentedPoint(trial_.w, w)
190 : sameRequestPoint(trial_.w, w))) {
191 sample = &trial_;
192 } else if (retain_samples_ && retained_.valid &&
193 sameRepresentedPoint(retained_.w, w)) {
194 sample = &retained_;
195 }
196 if (sample != nullptr) {
197 if (charge_work) logical_work_ += replayWork(*sample);
198 } else {
199 sample = &evaluate(w, charge_work);
200 }
201 if (logical_miss) {
202 request_ok_ = true;
203 if constexpr (holder_caches_samples_) {
204 // A domain rejection never enters the holder's own cache.
205 if (sample->holder_called) {
206 holder_request_ok_ = sample->retainable();
207 if (holder_request_ok_) holder_request_w_ = w;
208 }
209 }
210 }
211 if (seed_retained_ && sample->retainable()) {
212 retained_ = *sample;
213 seed_retained_ = false;
214 }
215 return *sample;
216 }

◆ logicalObjectiveWork()

template<typename ClassName, typename FuncName>
std::size_t funcmin::RgminNlmlCtx< ClassName, FuncName >::logicalObjectiveWork ( ) const
inlinenodiscardnoexcept

Definition at line 160 of file RgminObjective.h.

161 {
162 return logical_work_;
163 }

◆ physicalObjectiveWork()

template<typename ClassName, typename FuncName>
std::size_t funcmin::RgminNlmlCtx< ClassName, FuncName >::physicalObjectiveWork ( ) const
inlinenodiscardnoexcept

Definition at line 165 of file RgminObjective.h.

166 {
167 return physical_work_;
168 }

◆ pinAt()

template<typename ClassName, typename FuncName>
void funcmin::RgminNlmlCtx< ClassName, FuncName >::pinAt ( const Eigen::VectorXd & w)
inline

Pin only an evaluated sample; a step boundary never calls the holder. The first successful callback also pins a box-projected opening point.

Definition at line 150 of file RgminObjective.h.

151 {
152 if (!retain_samples_ || failure.failed()) return;
153 if (retained_.retainable() && sameRepresentedPoint(retained_.w, w))
154 return;
155 retained_.valid = false;
156 if (trial_.retainable() && sameRepresentedPoint(trial_.w, w))
157 retained_ = trial_;
158 }

◆ restoreHolderAt()

template<typename ClassName, typename FuncName>
rgmin_status_t funcmin::RgminNlmlCtx< ClassName, FuncName >::restoreHolderAt ( const Eigen::VectorXd & w)
inlinenoexcept

Cached first-order values do not restore mutable posterior state. This physical evaluation is separate from the solver's request budget.

Definition at line 220 of file RgminObjective.h.

221 {
222 if (failure.failed()) return RGMIN_INTERNAL_ERROR;
223 if (!retain_samples_ ||
224 (physical_ok_ && sameRepresentedPoint(physical_w_, w)))
225 return RGMIN_SUCCESS;
226 try {
227 return evaluate(w, false).retainable() ? RGMIN_SUCCESS
229 } catch (...) {
230 return captureCallbackError("final objective");
231 }
232 }
rgmin_status_t captureCallbackError(const char *callback) noexcept

Member Data Documentation

◆ exact_curvature

template<typename ClassName, typename FuncName>
const bool funcmin::RgminNlmlCtx< ClassName, FuncName >::exact_curvature

Definition at line 87 of file RgminObjective.h.

◆ failure

template<typename ClassName, typename FuncName>
RgminCallbackFailure funcmin::RgminNlmlCtx< ClassName, FuncName >::failure

Definition at line 106 of file RgminObjective.h.

◆ func

template<typename ClassName, typename FuncName>
const FuncName funcmin::RgminNlmlCtx< ClassName, FuncName >::func

Definition at line 85 of file RgminObjective.h.

◆ hessian_vector_fallback

template<typename ClassName, typename FuncName>
bool funcmin::RgminNlmlCtx< ClassName, FuncName >::hessian_vector_fallback = false

Set once the NLML Hessian-vector curvature callback has declined; rgmin then probes the gradient for every later curvature.

Definition at line 105 of file RgminObjective.h.

◆ holder

template<typename ClassName, typename FuncName>
ClassName& funcmin::RgminNlmlCtx< ClassName, FuncName >::holder

Definition at line 84 of file RgminObjective.h.

◆ map_cfg

template<typename ClassName, typename FuncName>
const MapObjectiveConfig& funcmin::RgminNlmlCtx< ClassName, FuncName >::map_cfg

Definition at line 86 of file RgminObjective.h.

◆ trace_evaluations

template<typename ClassName, typename FuncName>
bool funcmin::RgminNlmlCtx< ClassName, FuncName >::trace_evaluations = false

Definition at line 102 of file RgminObjective.h.

◆ x

template<typename ClassName, typename FuncName>
const gpr::EigenMatrix& funcmin::RgminNlmlCtx< ClassName, FuncName >::x

Definition at line 81 of file RgminObjective.h.

◆ x_ind

template<typename ClassName, typename FuncName>
const Eigen::VectorXd& funcmin::RgminNlmlCtx< ClassName, FuncName >::x_ind

Definition at line 82 of file RgminObjective.h.

◆ y

template<typename ClassName, typename FuncName>
const Eigen::VectorXd& funcmin::RgminNlmlCtx< ClassName, FuncName >::y

Definition at line 83 of file RgminObjective.h.


The documentation for this struct was generated from the following file: