Tuning toward a goal: minimise, maximise and set limits
"Tuning a parameter against measured data" answers one question: which values make my model reproduce this data? The same Parameter tuning card answers a second kind of question that needs no data at all: which values make my model do the best it can at something? Keep a temperature close to a target, reach the highest final value, stay under a ceiling while doing it. This page works through those cases on one small model, with the numbers each run produced.
The model
A hot plate held at 90 and a room that starts at 20, joined by a Cooling relationship with a rate of 0.05, as in "Getting started". Room air also has a source term, Ambient gain, which adds heat to the room at a constant rate. It starts at 0 and is marked tunable with bounds of -1 to 1, so it is the only thing the search may change. The Cooling rate is left alone.
Choose the goal and write the objective
Open Parameter tuning and choose Optimise an objective at the top of the card. The data file becomes optional.

An objective is a single number that the search makes as small or as large as it can. It is written in the equation editor, in Visual or LaTeX. A state changes over the whole run, so inside the objective it has to sit in a summary, and the buttons under the editor add them: final (the value at the end), max, min, mean and ∫ over the run (the value added up over time). Chips below insert the model's states and parameters by name, and the line under the editor says Valid objective or explains what is wrong.
Two more fields belong to the objective, because each trial is a full simulation: Each simulation runs for and Time step. Here they are 40 s and 0.1 s.
The first goal is to keep the room near 60 for the whole run. The objective is the total over the run of the squared distance from 60, and the Goal is Minimise:

Press Run fit. The chart shows every simulation as a dot and the best so far as a line:


The search found the best value of one constant for this objective. It did not find a room that sits at 60, because a single constant cannot lift the room quickly at the start and also stop it from overshooting later. When a result looks short of what you hoped for, check whether the parameters you allowed can do what the objective asks.
Maximise, and what the bounds do
Switch Goal to Maximise and ask for the highest temperature at the end of the run, final of the room's temperature. The review shows the objective as written, rising from 80.57 at the starting value to 97.88.

The gain ended at exactly 1, which is the upper bound. Nothing in the objective says where to stop, so the search goes as far as it is allowed to. The bounds are part of the question: widen them and the answer moves.
Set a limit
Often there is a ceiling. Press the plus beside Limits, write what to limit (here max of the room's temperature), choose stays at most and enter 65:

Run the same maximising goal again. The room now ends at 65.01 with the gain at -0.898, where before it ended near 98.

Two things to know about limits. First, they are penalties and not walls: breaking one makes the objective worse, so the search settles inside it when it can, and it can end a hair over. The card says All limits hold while the overshoot is under 0.1%, and here the room ended 0.04% over. Second, the starting value counts the penalty. Without tuning the room reaches 80.6, well over the ceiling, so the starting objective is shown as -4545 and the card reports a rise of 101%. Read that figure as "the starting values broke the limit", not as a measure of how much better the result is. If the limits cannot be met together with the parameters' bounds, the review says the best values still break one and by how much.
Mix in measured data
Data is optional, not forbidden. Add a CSV with Add measured data after choosing the goal, and a Measured data group of chips appears beside the states and parameters. Each column can be used in the objective, so the objective can compare the model with the data and add anything else it cares about.
Here the CSV is a room generated by the same model with an ambient gain of 0.3. With the plain squared error between the model and the data as the objective, the search recovers a gain of 0.296 and the objective falls from 534.6 to 0.008. Now add a preference for a small gain by adding 2000 times the gain squared:


The gain settles at 0.223 and the objective ends at 131.9, of which about 99 is the penalty itself. The weight is the trade-off: a larger one pulls harder toward a small gain at the cost of a worse fit, and a smaller one lets the data win. Nothing in the objective is special about that term, so the same pattern works for any cost you want to weigh against the fit.
Watching a long search
The runs above took under a tenth of a second. A model that takes seconds per simulation turns the same search into minutes or hours, and the card is built for that. Before the first trial it times one simulation and says what the limits imply, and while it runs it shows the rate, the best value so far, how far that is from the start and the parameter values. A chip in the toolbar status area follows the search with the simulation count and the best value.
To see it, the same first goal was run with ISRES, a global search, and a limit of 200000 simulations:

The card estimated about 18 minutes for the full limit, and after a few seconds it warned that nothing had improved for several hundred simulations, which usually means the search has found what it can. Stop and use best so far ends the search and goes to the review with the best found. Apply best so far ends it and applies those values to the model straight away, and Discard throws the tuning away.

The result is a gain of -0.5215, the same value the faster search found in 16 simulations. A global search that agrees with a local one is a reassuring sign that the answer is the best this objective has to offer. The Time limit field next to the simulation limit stops a search after a set number of minutes.
What to remember
- An objective is one number: a state has to sit inside a summary, and the editor says when it does not.
- Maximise shows the real value, rising. A result at a parameter's bound means the bound decided the answer.
- Limits are penalties. The search can end slightly over, and the starting value includes the penalty.
- Data is optional and can be combined with any other terms. A weight is how much each term counts.
- A long search can be stopped at any time with the best so far kept. The setup is saved with the project, so reopening the card restores the goal, the objective and the limits.
Where to go from here
"Tuning a parameter against measured data" covers the other goal, in which the answer is whatever reproduces a CSV. "Sharing one parameter across relationships" explains how a parameter used in several places becomes a single thing to tune. The comic "I had a goal and no data. Now what?" tells the first example as a short story.
Follow Konjugate on LinkedIn for updates, or subscribe via RSS.
Comments
Post a Comment