Skip to main content

Module optimize

Module optimize 

Source
Expand description

Optimization: the design variables that make a model’s output as small as it can be.

Guide: Optimization runs the optimizer on test functions whose minima are known, then finds the ballast and body length that send a rocket to 3,048 m, chooses a motor and a catalog nose cone for it, traces a rocket’s trade-off between apogee and stability, and says how far to trust it.

  • Variable: one number the optimizer may change, with where it starts, the size of its first steps, and optional bounds. An integer variable (Variable::integer) takes whole numbers only: a count, or a choice from a list, such as a motor or a catalog part.
  • cmaes: the covariance matrix adaptation evolution strategy (CMA-ES), which samples candidates around a mean, keeps the better half, and learns from them which way, and how far, to step next. It needs only the output’s ranking, no derivatives, so it suits flights, whose outputs are noisy in their last digits.
  • nsga2: NSGA-II, a genetic algorithm for two or more goals at once (apogee against stability, say), which finds the Pareto front: the designs where one goal can only be bettered by giving up another.
  • ego: efficient global optimization (EGO), for a model so slow that only tens of evaluations can be afforded: it fits a surrogate to the points evaluated so far and evaluates next where the surrogate expects the most improvement.
  • Evaluation: a value and a constraint violation, for a model with constraints, ranked by Deb’s feasibility rules (cmaes::Run::tell_constrained).
  • benchmark: test functions with known minima, and test problems with known fronts, which the tests hold the optimizers to.

A model is minimized; to maximize an output, minimize its negative. To hit a target, minimize the squared miss, as the guide’s example does.

§Reproducibility

A run is drawn from a seed. Each CMA-ES candidate has its own random stream (SeededRng::for_stream), keyed by the seed, its generation and its place in the generation, and each NSGA-II generation has one stream, so a run is bit for bit the same every time on one platform, however its candidates are evaluated.

§Left out

EGO is checked on two and three variables only (on six it often stops at a local minimum), and optimizing a Monte Carlo run’s statistics is a later increment of M6.2, the optimization milestone.

Modules§

benchmark
Test functions with known minima, for checking an optimizer.
cmaes
The covariance matrix adaptation evolution strategy (CMA-ES).
ego
Efficient global optimization (EGO): minimizing a model that is slow to evaluate in few evaluations, by fitting a surrogate to the points evaluated so far and evaluating next where the surrogate expects the most improvement.
nsga2
NSGA-II, the non-dominated sorting genetic algorithm II: a search for the designs that trade two or more goals off against each other, the Pareto front.

Structs§

Evaluation
What a model gives for one candidate under constraints: its value, and by how much it breaks the constraints, zero if it keeps them all.
Variable
A number the optimizer may change: its name, where it starts, the size of its first steps, the range it must stay in, and whether it takes only whole numbers. It serializes as its fields (an unbounded side as null; integer only when true, and read as false when absent), and reads back through Variable::new, Variable::within and Variable::integer’s checks.

Constants§

MAX_VARIABLES
The most variables an optimizer takes. CMA-ES holds an n × n covariance and decomposes it each generation, O(n³) work; 200 variables is far more than a rocket design has.