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).
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.
The following are valid optimization routines:
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
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
iterations: number of circuits that will be evaluated with randomized values
Description: simplex is a non-linear gradient search
Able to optimize over both linear and discrete values simultaneously
Deterministic solution- not random
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)
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)
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.
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
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