Optimization Block


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:

Optimizing using Mason

Optimizing the design requires a fair amount of setup. This page provides an overview of the steps needed, and links to more details where needed. The first part of this page will detail using TinyCAD to optimize, and in the bottom of the page will detail the low level text file syntax needed for running from the console.

See also the page on optimization sets, an advanced tool in Mason.

1) Defining the Variables of Optimization

In TinyCAD, the optimization and statistical tags are added after the variable of the device arguments, with a semicolon or colon between the value and the optimization and/or statistical tags. Everything after the semicolon or colon is directly injected into the Mason XML file. If a semicolon is used, then the optimization tag will not be displayed in the schematic. If the colon is used, then the optimization tag will be displayed in the schematic.

Primitive components can also embed the parameters for statistical analysis and optimization in their definitions. Two flags are available, “opt” and “stat”:

Click on this picture to enlarge

It is not necessary to have both tags: one can add either the optimization tag, or the statistical tag, or both may be present. It is necessary to have the value defined. Statistical and optimization tags may be assigned within the variable block, or for a device's parameters. If a device parameter is set with a variable, the optimization and statistical tags must be defined in the variable block with that variable.

Note that “opt” and “stat” do not both need to be set. If the “step” is not set for either optimizations or statistical analysis, or the step is set to zero, then the values are allowed to be continuous. The standard deviation may be set as an absolute value or it may be set as a percent of the value at the time of analysis (and not necessarily at the initial value set in the XML file). Files should have the step set to one (or not set at all, since that's the default for files).

2) Defining the optimization

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... but it's not a good idea to risk errors in that way.

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. Check out the math parser page for valid calculation functions.

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).

Optimizer 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:

    1. single

        1. Description: performs a single run on the current values

          1. If no optimizations are defined, a single run will be performed by default

          2. 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

        2. Inputs

            1. None

    2. random

        1. Description: uses random numbers to guess at a solution

          1. Fills the device values with a random uniform distribution

          2. Uses the minimums, maximums and steps defined in each variable or device's parameter

        2. Inputs

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

    1. simplex

        1. Description: simplex is a non-linear gradient search

            1. Able to optimize over both linear and discrete values simultaneously

            2. Deterministic solution- not random

        2. Inputs

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

            2. 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)

    1. step (see validation18.txt)

      1. Description: sweep through the first two valid optimization parameters

        1. Sweeps an <opt> tag from a variable or an <opt> tag embedded in a device argument

        2. Steps from opt_min to opt_max, step must be non-zero

        3. Outputs two or three MATLAB compatible files

          1. If only one parameter swept, a *.x and a *.z file

          2. If two parameters swept, a *.x, *.y, and *.z file (can be used in mesh/ surf command)

      2. Inputs

        1. none

    1. genetic (see validation23.txt)

        1. Description: genetic algorithm

          1. ensures that every member evaluated is unique by forcing mutations if a member has already been tried.

          2. uses proportional selection. Eventually I'll add the option for other selection schemes like tournament or flat.

          3. uses elitism: the number of best people kept to the next generation is controlled with a flag.

          4. 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).

          5. Rank selection/ weak Pareto-optimization is coded in, use the "rank" flag

          6. I don't have a micro GA coded in yet, but running multiple GAs during a run is advised and has a similar effect.

        2. 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.

        3. Inputs

          1. iterations: number of generations

          2. population (default 100): size of the population

          3. rank (default false): if true, use the ranking algorithm (aka weak pareto) for the GA

            1. Note that number_of_best_kept behaves a little differently between ranking and not

          4. 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.

          5. 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).

        1. 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.

          1. 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.

        1. 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).

        2. 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.

        3. selection (default proportional): One of three types of selection algorithms for choosing mates for crossover

          1. "flat": each element has equal weighting

          2. "proportional": elements have weighting proportional to their normalized figure of merit (note: if ranking used, proportional to rank)

          3. "tourney": use the tourney algorithm

        1. tourney_size (default 1): size of the tournament used in selection (if tourney used).

        2. A reasonable starting place for your GA is:

          1. genetic iterations=100 population=100 first_generation_multiplier=4 selection=tourney tourney_size=5

          2. Feel free to experiment, I have good luck starting with this

Optimization sets for parameters and Figures of Merit

See also the page on optimization sets, an advanced tool in Mason.

Copyright 2010, 2011, 2012 Gregory Kiesel