# Optimizers

Only one optimization block is allowed; however, multiple optimization routines may be specified. Mason will run each optimizer in sequence. Each optimizer allows a set number of arguments; generally the number of iterations is considered a maximum. The optimizer works to minimize the goals. The “power” argument defaults to 2, and refers to how the goal functions are summed:The optimizer can be run from the GUI.

The goal block includes a muParser-style calculation, with a minimum and maximum desired range. If multiple goals are given, the evaluations are summed. The S-Parameters for the goals follow the pattern [{S_reflected_driven}], as below.

<optimization>

<random iterations="100”></random>

<simplex iterations=”100” power=”2”></simplex>

<goal calculation=”20*log10(abs(S_1_1))”

min=”-200”

max=”-20”

weight=”1”></goal>

</optimization>

The goals can be tailored to only apply for certain frequencies. See the the goals section for more information.

Look at the device section to see how to embed optimization limits for particular parameters.

### TinyCAD

The optimization block looks as follows in the GUI, essentially everything in the TinyCAD component is pasted into the Mason file and follows a fairly logical progression. Do not include more than one optimization block, I've put a few to show a couple of different strategies.Genetic has the most options. Generally you can get away with not putting values in quotes, but if a space is involved in the value (like "5 %"), then quotes are needed. Technically, you could use 5% and not have a space...

When you click on the optimization component, the following window pop-ups (click to enlarge). Initially only one Optimizer and one Argument are defined. Below, a second optimizer has been added using the Add button in the bottom left.

### Turning Goals Temporarily Off

In TinyCAD, goals (and specific optimizer steps) can be turned off by clicking on the "Show?" field for that goal (or optimization step).

### Details

Each frequency is evaluated for the goals, and the deviations from the goal at each frequency is squared, summed, and rooted. This sum is the Figure of Merit (expect when the ranking algorithm is used in the Genetic Algorithm).After each optimizer is run, the best values (based on the figure of merit) is propagated to the next optimization.

See also: Goals for optimizations and statistical analysis, and Sets

The following are valid optimization routines:

- single
- Description: performs a single run on the current values
- If no optimizations are defined, a single run will be performed by default
- If optimizations are defined, a single run is performed at the beginning and at the end of the optimization sets, to ensure the output data corresponds with what's in the files
- Inputs
- None

- Description: performs a single run on the current values
- random
- Description: uses random numbers to guess at a solution
- Fills the device values with a random uniform distribution
- Uses the minimums, maximums and steps defined in each variable or device's parameter
- Inputs
- iterations: number of circuits that will be evaluated with randomized values

- iterations: number of circuits that will be evaluated with randomized values

- simplex
- Description: simplex is a non-linear gradient search
- Able to optimize over both linear and discrete values simultaneously
- Deterministic solution- not random

- Able to optimize over both linear and discrete values simultaneously
- Inputs
- iterations: number of times the simplex algorithm is called; generally speaking one is enough
- tolerance (default 1e-6): when the difference between the gradient steps of the normalized FOM drops below this value, stop the optimizer. The value is compared against the current gradient step divided by the allowable spread: delta/(opt_max-opt_min)

- iterations: number of times the simplex algorithm is called; generally speaking one is enough

- Description: simplex is a non-linear gradient search
- step (see validation18.txt)
- Description: sweep through the first two valid optimization parameters
- Sweeps an <opt> tag from a variable or an <opt> tag embedded in a device argument
- Steps from opt_min to opt_max, step must be non-zero
- Outputs two or three MATLAB compatible files
- If only one parameter swept, a *.x and a *.z file
- If two parameters swept, a *.x, *.y, and *.z file (can be used in mesh/ surf command)
- Inputs
- none
- genetic (see validation23.txt)
- Description: genetic algorithm
- ensures that every member evaluated is unique by forcing mutations if a member has already been tried.
- uses proportional selection. Eventually I'll add the option for other selection schemes like tournament or flat.
- uses elitism: the number of best people kept to the next generation is controlled with a flag.
- uses two types of mutation. One is a traditional mutation, a random generation on an individual gene (somewhere between the defined max and min). The seconds is a creep, a mutation with a smaller variance centered on the current value (allows for searching the space close to an established solution).
- Rank selection/ weak Pareto-optimization is coded in, use the "rank" flag
- I don't have a micro GA coded in yet, but running multiple GAs during a run is advised and has a similar effect.
- Comment: To be honest, random + simplex will very often be more efficient that a genetic algorithm. Genetic algorithms are useful at solving problems that have no gradient; most circuit problems actually are amenable to gradient type searches.
- Inputs
- iterations: number of generations
- population (default 100): size of the population
- rank (default false): if true, use the ranking algorithm (aka weak pareto) for the GA
- Note that number_of_best_kept behaves a little differently between ranking and not
- first_generation_multiplier (default 4): the first generation will contain a number of citizens equal to "population" times "first_generation_multiplier". Subsequent generations will contain "population" citizens.
- mutation_rate (default 0.1%): mutation rate, can be entered as "0.001" or "0.1 %" (you can use percent sign as a unit) ; probability cast against each gene that the gene will be re-rolled (completely new, random value which still falls in the valid range).
- number_of_best_kept (default 1): relevant after a population has been evaluated. If ranking used: citizens with this rank or lower will be passed on to the next generation. If ranking not used: this many citizens will be passed on to the next generation.
- Note that for ranking, a value of 1 will still keep a bunch of citizens. Be careful not to set this too high when switching to ranking.
- creep_rate (default 0.1 %): creep rate, can be entered as "0.001" or "0.1 %"; probability cast against each gene that the value will be modified. Value will be multiplied against a random uniform distribution with a mean about the current value and a range that is (creep_amount * current_value).
- creep_amount (default 10 %): percent of the range for the value (opt_max - opt_min) that will make up the range for a random change in value.
- selection (default proportional): One of three types of selection algorithms for choosing mates for crossover
- "flat": each element has equal weighting
- "proportional": elements have weighting proportional to their normalized figure of merit (note: if ranking used, proportional to rank)
- "tourney": use the tourney algorithm
- tourney_size (default 1): size of the tournament used in selection (if tourney used).
- A reasonable starting place for your GA is:
- genetic iterations=100 population=100 first_generation_multiplier=4 selection=tourney tourney_size=5
- Feel free to experiment, I have good luck starting with this