8#include <unordered_map>
16using MetricMap = std::unordered_map<std::string, double>;
68 std::size_t
offset() const noexcept {
return offset_; }
101 const std::string&
source() const noexcept {
return source_; }
103 const std::vector<std::string>&
identifiers() const noexcept {
return identifiers_; }
107 std::unique_ptr<detail::ExpressionNode> root_;
108 std::vector<std::string> identifiers_;
159template <typename Observation>
Parse error raised while compiling a metric expression.
ExpressionError(std::string message, std::size_t offset)
Constructs an error whose what() text includes the byte offset.
std::size_t offset() const noexcept
Returns the zero-based byte offset in the original expression.
Parsed metric expression that is compiled once and evaluated repeatedly.
MetricExpression(std::string source)
Parses and compiles source.
MetricExpression(MetricExpression &&) noexcept
ExpressionEvaluation evaluate(const MetricMap &metrics, const EvaluationPolicy &policy={}) const noexcept
Evaluates the compiled expression without throwing.
const std::vector< std::string > & identifiers() const noexcept
Returns unique metric identifiers in first-appearance order.
const std::string & source() const noexcept
Returns the original expression text.
EvaluationError
Stable reason code for an invalid ExpressionEvaluation.
@ DivisionByZero
Division by zero was rejected.
@ NonFiniteMetric
A referenced metric violated the non-finite metric policy.
@ None
Evaluation succeeded.
@ MissingMetric
A referenced identifier was absent from the metric map.
@ NonFiniteResult
Evaluation failed or produced a disallowed non-finite result.
std::function< ObjectiveResult(const Observation &, const TrialContext &)> ObjectiveFn
Type-erased custom objective accepting an observation and immutable trial context.
NonFinitePolicy
Behavior when a metric or expression result is not finite.
@ Allow
Preserve the non-finite value for the caller.
@ Reject
Reject the non-finite value.
std::unordered_map< std::string, double > MetricMap
Metric values keyed by canonical objective path.
ConstraintRelation
Comparison relation applied by Constraint.
@ GreaterEqual
Require lhs >= rhs - tolerance.
@ LessEqual
Require lhs <= rhs + tolerance.
@ Equal
Require abs(lhs - rhs) <= tolerance.
DivisionByZeroPolicy
Behavior when an objective expression divides by zero.
@ Ieee754
Permit IEEE-754 infinity or NaN, subject to the result policy.
@ Reject
Return an invalid ExpressionEvaluation.
Named scalar feasibility constraint with an absolute non-negative tolerance.
double rhs
Configured right-hand side.
double lhs
Evaluated left-hand side.
std::string name
User-facing constraint identifier.
ConstraintRelation relation
Required comparison relation.
double violation() const noexcept
Returns zero when satisfied and the positive violation magnitude otherwise.
double tolerance
Absolute tolerance; negative values are treated as zero.
bool satisfied() const noexcept
Returns whether all operands are finite and the relation holds.
Policies controlling exceptional arithmetic during metric-expression evaluation.
DivisionByZeroPolicy division_by_zero
Division-by-zero behavior.
NonFinitePolicy non_finite_result
Behavior for a non-finite final expression value.
NonFinitePolicy non_finite_metric
Behavior for a referenced non-finite metric.
Non-throwing result envelope returned by MetricExpression::evaluate().
EvaluationError error
Machine-readable failure reason, or EvaluationError::None.
double value
Evaluated scalar; meaningful only when valid is true.
bool valid
True only when value is usable under the selected policy.
std::string diagnostic
Human-readable failure detail, empty after successful evaluation.
Objective values, constraints, and diagnostics produced for one observation.
std::string diagnostic
Human-readable invalid-result detail.
std::vector< Constraint > constraints
Feasibility constraints evaluated alongside the objective.
bool feasible() const noexcept
Returns true when valid, non-empty, finite-valued, and all constraints pass.
std::vector< double > values
Objective vector; the current native samplers consume one value.
Metadata supplied to a custom objective while evaluating one trial.