Skip to content

Optimization

ChristopherMayes edited this page Sep 5, 2017 · 7 revisions

Setup with the 'use' and 'veto' commands

To optimize we need to specify how to construct a merit function, and what variables to use that change the merit function. The merit function is constructed from individual datums, defined in the init file as described in Data & Variables in Tao and the Tao manual. These datums are flagged for use in the merit function with the 'use' and 'veto' commands as:

Tao> veto dat *
  twiss.end[1:6]                                 Using:
  twiss.max[1:2]                                 Using:

Tao> use dat twiss.end[1:4]
  twiss.end[1:6]                                 Using: 1:4
  twiss.max[1:2]                                 Using:

Their contribution to the merit function can be seen with:

Tao> show top

! Top 10

Constraints                     Ref_Ele    Start_Ele    Ele/S     Target      Value      Merit     Max
twiss.end[3]  beta.b <target>                         END       1.250E+01   1.744E+00  1.16E+03
twiss.end[4]  alpha.b <target>                        END      -1.000E+00  -4.705E-01  2.80E+01
twiss.end[1]  beta.a <target>                         END       1.250E+01   1.189E+01  3.69E+00
twiss.end[2]  alpha.a <target>                        END      -1.000E+00  -1.174E+00  3.03E+00
Constraints                     Ref_Ele    Start_Ele    Ele/S     Target      Value      Merit     Max

 figure of merit: 1.191577E+03

List of non-zero contributors to the Merit Function:
Name                                          Merit           Sigma [= sqrt(Chi^2/N)]
twiss.end                                     1.1916E+03      5.3935E+00

The use command works similarly with variables: Tao> use var * quad[1:6] Using: 1:6

Tao> veto var quad[2,3]
  quad[1:6]                                      Using: 1 4:6

Optimizer selection

Tao offers several optimizers

lm    ! Levenburg-Marquardt algorithm as implemented in Numerical Recipes. 
lmdif ! Variant of lmdif that does not build the derivative matrix separately
de    ! Differential evolution genetic optimization algorithm.
svd   ! Forms a pseudo-inverse matrix a from singular value decomposition of the derivative matrix.

These are chosen with the set command:

Tao> set global optimizer = de

Generally speaking, 'lm' and 'lmdif' are useful for local optimization, and 'de' is useful for global optimization. The 'svd' method is useful for nearly-linear problems, such as orbit correction.

The 'de' optimizer often needs to take coarser steps than the lm optimizers. The %step is a property of the variable. This coarseness is governed by the 'de_lm_step_ratio' with the set command:

set global de_lm_step_ratio = 1000

Often the user needs to play with this number quite a bit. An alias makes this easy:

alias sde set global de_lm_step_ratio = [[1]]

So that the previous statement is simply:

sde 1000

Run

Tao> run
Optimizing with: de
Type ``.'' to stop the optimizer before it's finished.
Differential evolution optimizer, population: 30
****************************************************
 So far the minimum is   1.191577E+03
****************************************************
****************************************************
 So far the minimum is   1.162380E+03
****************************************************
****************************************************
 So far the minimum is   1.090154E+03