Feature#
- class Feature#
FEATURE Reusable specification of ordered problem transformations.
A Feature owns configuration, not an experiment or a live random stream. Each effective stage has its own validated local options. FeaturedProblem builds fresh execution state from the specification for each trial.
Construction
F = Feature(NAME) accepts an atomic char/string name or names joined with ‘+’. The first name is applied first: ‘noisy+truncated’ adds noise and then truncates the observed value. Names are trimmed and lowercased.
F = Feature(NAME, OPTIONS) accepts a scalar struct of local options. F = Feature(NAME, KEY, VALUE, …) accepts the same options as name/value pairs. A supplied option is broadcast to every declared stage that accepts it; each stage validates it separately. An option accepted by no stage is an error. Repeated stages share these flat supplied values. Option names are case-insensitive; two spellings of one name in the same struct or name/value list are rejected as a duplicate (the configuration would be ambiguous).
F = Feature(STAGE) accepts a scalar struct with fields ‘name’ and optional ‘options’ (a scalar struct). F = Feature(STAGES) accepts a nonempty cell array of atomic names or such structs, in order. This form gives repeated stages independent options. Extra flat options, struct arrays, internal stage records, and empty specifications are not accepted. Stage names in structured input must be atomic, not joined with ‘+’.
F = Feature(EXISTING_FEATURE) returns the existing canonical Feature without normalizing it again. No extra options are accepted in this form. Feature() without a specification is an error; use Feature(‘plain’).
‘plain’ entries are validated before being removed. An all-plain declaration has zero effective stages, while the declaration remains available for inspection. Any number of stages is allowed and names may repeat. For example:
F = Feature({ ... struct('name','noisy','options',struct('noise_level',1e-2)), ... 'plain', ... struct('name','noisy','options',struct('noise_level',1e-4))});
Experiment options
n_runs is never a Feature option, including inside a stage. Supply it to benchmark instead, for example:
options = struct('feature', F, 'n_runs', 3); scores = benchmark({@solver1, @solver2}, options);
At the benchmark boundary, ‘feature’ and ‘feature_name’ are mutually exclusive. ‘feature’ accepts a Feature or structured stages, not a bare shorthand string, and cannot be combined with flat local options or load. The experiment layer resolves repetition defaults and the independent plain-reference role; stochastic classification alone does not determine the run count. Experiment-wide controls such as seed are not stage options.
Built-in stages and all local options
The following defaults are local to one stage. A missing local OPTIONS struct uses these defaults. No stage stores n_runs. Numeric options must be finite real scalars and are stored as double; integer-class values must be exactly representable as double. Logical options accept true/false or numeric 0/1 and are stored as logical. Text choices are lowercase and case-sensitive.
‘plain’: the identity; no local options.
‘perturbed_x0’: perturb the initial point. ‘distribution’ defaults to ‘spherical’; alternatives are ‘gaussian’ or a function handle accepting (random_stream, dimension) and returning a perturbation vector. ‘perturbation_level’ is a finite, nonnegative scalar magnitude factor (default 1e-3), scaled by max(1, norm(problem.x0)). MATLAB accepts no vector amplitudes.
‘noisy’: modify observed objective and nonlinear-constraint values. ‘distribution’ defaults to ‘gaussian’; alternatives are ‘uniform’ or a function handle accepting (random_stream, output_size). ‘noise_level’ is a finite, nonnegative scalar (default 1e-3). ‘noise_type’ is ‘absolute’, ‘relative’, or ‘mixed’ (default ‘mixed’). ‘noise_mode’ is ‘random’ (default) or ‘deterministic’. In deterministic mode, ‘noise_map’ is ‘chebyshev’ (default) or a function handle x -> real scalar. The named noise map is not used in random mode.
‘truncated’: truncate observed objective and nonlinear-constraint values. ‘significant_digits’ is the retained number of significant digits, a positive integer (default 6). ‘perturbed_trailing_digits’ controls randomization of the trailing digits (default false).
‘permuted’: randomly permute variables and transport the initial point, bounds and constraints consistently; no local options.
‘linearly_transformed’: apply an invertible linear coordinate change. ‘rotated’ controls random rotation (default true). ‘condition_factor’ is a finite, nonnegative scalar (default 0); the existing transformation has condition number 2 ^ sqrt(condition_factor * n / 2) for dimension n >= 2, and 1 for n = 1.
‘random_nan’: replace observed objective and nonlinear-constraint values by NaN with probability ‘nan_rate’, a finite value in [0, 1] (default 0.05). These NaN observations are the feature’s output; a NaN option value is a configuration error.
‘unrelaxable_constraints’: set the observed objective to Inf when a selected category of predecessor constraints is violated. ‘unrelaxable_bounds’ defaults to true; ‘unrelaxable_linear_constraints’ and ‘unrelaxable_nonlinear_constraints’ default to false.
‘nonquantifiable_constraints’: return 0 when cub <= 0 or abs(ceq) <= 1e-6, and 1 otherwise, retaining undefined values as NaN; no local options.
‘quantized’: evaluate at a point snapped to a mesh. ‘mesh_size’ is a finite, positive scalar (default 1e-3); ‘mesh_type’ is ‘absolute’ (default) or ‘relative’. ‘ground_truth’ defaults to true: the local reference objective and nonlinear constraints also use the snapped point. With false, only observations are snapped. Bounds and linear constraints are assessed at the unsnapped point in that stage’s coordinate system.
‘custom’: user-supplied modifier function handles, listed below. Omitted modifiers use the runtime’s default behavior; a supplied mod_affine still changes coordinates and transports omitted structural components.
Custom local options have these signatures; random_stream is supplied by the runtime, and problem is the stage’s immediate predecessor Problem:
mod_x0: (random_stream, problem) -> modified_x0 mod_affine: (random_stream, problem) -> (A, b, inverse_A) mod_bounds: (random_stream, problem) -> (modified_xl, modified_xu) mod_linear_ub: (random_stream, problem) -> (modified_aub, modified_bub) mod_linear_eq: (random_stream, problem) -> (modified_aeq, modified_beq) mod_fun: (x, random_stream, problem) -> modified_fun mod_cub: (x, random_stream, problem) -> modified_cub mod_ceq: (x, random_stream, problem) -> modified_ceq
mod_affine supplies the coordinate map A*x+b and a candidate inverse. It is asked once per problem and seed, and the initial point, the bounds, the linear constraints and every evaluation use that one answer. The triple is validated when the problem is built: real, finite arrays of matching sizes, norm(abs(inverse_A)*abs(A),inf) < 1/eps, and the two inverse residual checks norm(max(abs(A*inverse_A-eye(n)) - 64*n*eps*abs(A)*abs(inverse_A),0),’fro’) <= 1e-8*n and the same for inverse_A*A. These matrix-test quantities must be finite; eps is for double precision. Independently, rows then columns of A are scaled by powers of two to form E without losing entries, and rcond(E) > eps is required. These numerical checks are not a proof of an exact inverse. Inputs are converted to double precision before validation and use. If A is exactly diagonal and diag(inverse_A) is its reciprocal to roundoff, the bounds stay bounds; otherwise every finite bound is posed as a linear constraint, so an off-diagonal entry of A is never ignored, however small. Transport rejects finite bounds, coefficients or right-hand sides becoming non-finite, nonzero scaled bounds below realmin, and row or right-hand-side entries whose sum of absolute nonzero product terms lies below realmin. A strict original bound interval must not collapse after translation or diagonal scaling. These are stage-local safeguards, not an exact transport certificate. Unless mod_x0 is supplied, finite original x0 keeps y = inverse_A*(x0-b) unchanged only if y, its mapped point and the rounding allowance are finite, and abs(A*y+b-x0) is at most both 64*n*eps*(abs(A)*abs(y)+abs(b)+abs(x0)) and sqrt(eps)*min(abs(x0),abs(x0-b)), componentwise, with no absolute floor. An error at a zero coordinate of either x0 or x0-b triggers a solve. Both scales are checked so a large coordinate origin cannot hide error in a small centered value. If either check fails, A*y = x0-b is solved independently and the solved point is checked for finiteness and the rounding allowance only; failure raises an initial-point error. The extra local threshold triggers a solve instead of trusting the inverse candidate; it is not a bound on the final forward error. Even an honestly computed inverse may trigger a solve, for example when a custom rotation mixes small and large coordinates. Intrinsic conditioning or mixed coordinate scales can cause forward drift even after solving. Initial truth evaluation uses the posed start; the existing single-stage fallback retries the original initial point when an evaluation returns an empty result. Thus fun_init and maxcv_init do not certify recovery of an originally feasible point. Since mod_linear_ub and mod_linear_eq replace linear constraints, they are refused if they would remove generated bound rows, unless mod_bounds also takes ownership of the bounds. mod_bounds replaces the bounds and nothing else: under an A for which the bounds stay bounds they are replaced, under any other A they are not re-added as generated rows; explicit linear constraints are still transported. The derivative methods of a featured problem follow the same transformation by the chain rule (see FeaturedProblem). Construction checks do not recompute initial points or histories in previously saved experiments or built objects; loading is not a migration of old results. Within an observation callback, querying problem.fun/cub/ceq serves that predecessor again; these calls are not silently treated as reference reads.
Inspection, transport and compatibility
Read-only properties are ‘stages’, ‘declared’, ‘name’, ‘declared_name’, ‘is_stochastic’, ‘is_identity’ and ‘specification_version’. ‘stages’ is a cell array of effective records with name, occurrence (same-kind zero-based index), identity (for example ‘noisy#0’), literal code and normalized local options. The effective ‘name’ joins those stages, or is ‘plain’ for identity. ‘is_identity’ tests for zero effective stages. ‘is_stochastic’ reports the stages’ established classification (custom is classified as stochastic), not the number of actual executions or a guarantee of independent draws.
‘declared’ retains a route (‘feature_name’ or ‘feature’) and entries with supplied name/options before defaults, including plain entries; ‘declared_name’ joins those declared names. An imported historical Feature with no recorded declaration has declared=[] and declared_name=’’. The specification’s declaration route is distinct from the benchmark keyword through which an existing Feature is later supplied.
Returned records and option structs are value copies. Native function handles and handle-valued user state remain references; Feature does not promise deep immutability of a callback’s captured state. Normalization does not invoke callbacks; their outputs are checked during execution.
Current native save/load transports versioned, resolved effective options and the separately retained declaration, not runtime counters or streams. The known old stored name/options layout loads into a LegacyFeatureEnvelope. optiprofiler_internal.importLegacyFeature converts that envelope to a clean Feature plus a separate retained experiment request; an old resolved count is not proof that the old caller requested it explicitly. For saved options, loadBenchmarkOptions prepares a fresh benchmark rather than replotting or resuming a live runtime. Native MAT loading is trusted input and can execute code; original callback/class dependencies must be available. JSON callback descriptions are not executable reconstruction recipes.
‘options’ and modifier_x0/affine/bounds/linear_ub/linear_eq/fun/cub/ceq are deprecated identity/single-effective-stage conveniences. They warn, and accessing them for multiple effective stages is an error. The hidden ‘options’ property is not shown when a Feature is displayed. Each modifier call creates a fresh numerical kernel; the engine does not use these conveniences to execute a pipeline. Use FeaturedProblem for execution. In particular, a kernel keeps the transformation of mod_affine for one problem and seed, so that the initial point, the bounds, the linear constraints, the derivatives and every evaluation of a FeaturedProblem share one map, whereas each of these conveniences asks mod_affine again: a callback with a state can give two of them two different maps.