WIDesigner Optimizers - edwardkort/WWIDesigner GitHub Wiki

Introduction

Each of the WIDesigner study models provides a set of optimizers. Each optimizer varies specific dimensions of an instrument, looking for the best match to a selected tuning.

What WIDesigner Optimizes

Almost exclusively, WIDesigner optimizers are minimizing the sum of squares of differences, in cents, between WIDesigner's predicted frequency and the target frequency in the tuning, for all the notes of the scale. In the tuning file, you can assign weights to the notes of the scale. At this time, WIDesigner optimizes only for tuning, without regard to tone colour or playability.

What the Optimizer Changes

The independent variables are always specific values in the instrument geometry, and always subject to upper and lower bounds. Sometimes the values are direct: for example, the diameter of tonehole B2 varied between 4 mm and 10.5 mm. Some values are more indirect: rather than the absolute position of B2, the relative spacing between B2 and B3, varied between 12 mm and 37.5 mm; rather than the absolute bore diameter at point x, the ratio of the bore diameter at point x to the bore diameter at the next point down, varied between 0.5 and 1.0. As far as possible, we have chosen the values so that the upper and lower bounds reflect physical realities: the size of your fingertips, how far apart you can spread them, whether the bore is expanding or contracting, etc. For more information about constraints, see the Optimization Constraints page.

For details of what each optimizer varies, see:

As far as possible, avoid under-determined optimization problems, where you have more values to vary than notes to optimize. For example, if you optimize 6 toneholes (13 variables) to tune only one octave (8 notes), you can get perfect results with any number of different geometries. Add in a cross-fingered note or two, and you can still get great results. But notes in the second register will be all over the place. And under no circumstances try to optimize bore diameters at 320 individual points on the bore, without very tight constraints on the diameter ratios.

The Console Log

When each optimization starts, WIDesigner logs the following messages on the Console panel:

  • The number of optimization variables and the number of target notes included in the optimization.
  • The initial value of the error function that will be optimized, on the starting geometry. If the instrument geometry you start with violates one of the optimizer constraints, WIDesigner will adjust the geometry to one that is within the constraints before it starts the optimization.

When an optimization finishes, WIDesigner logs these messages:

  • The number of individual tuning calculations performed in the course of the optimization, and the number of times the error function was calculated. The second number is the number of different instrument geometries WIDesigner tested in looking for the best geometry.
  • The final value of the error function, on the final geometry, and the ratio of the final error to the initial error. The closer this ratio is to zero, the more successful the optimizer has been. If this ratio is 1.0 or more, the optimizer hasn't improved the tuning at all.
  • The elapsed time for the optimization run.

Optimization Algorithms

We have settled on three standard optimization algorithms. If there is only one independent variable, WIDesigner uses a univariate optimization algorithm by Richard Brent, described in his book, Algorithms for Minimization without Derivatives.

For more than one variable, the workhorse algorithm is a local optimization algorithm by Michael Powell called BOBYQA (Bounded Optimization BY Quadratic Approximation), described in a 2009 Cambridge University report, The BOBYQA algorithm for bound constrained optimization without derivatives. BOBYQA is good at finding a local optimum near the starting point, not so good at looking for better solutions farther afield. In some cases, if you run a second optimization from the new starting point, or a different starting point, you will get better results.

For a really thorough exploration of the search space, WIDesigner can use a global optimization algorithm, DIRECT-C, that is a variant of the DIRECT (DIViding RECTangles) global optimization algorithm by Jones, Perttunen and Stuckman. See the Bibliography for our sources. Unlike BOBYQA, DIRECT-C is not dependent on the starting position. It is, however, very dependent on the constraints: the upper and lower bounds you use can make the difference between success and failure with DIRECT-C.

None of these algorithms use Monte Carlo methods or randomness; for better or worse, if you repeat an optimization exactly, you'll get the same result every time. We have tried an algorithm that involved random sampling; it wasn't as fast or dependable as BOBYQA, and the variability of results was disconcerting.