Nonlinear Optimization block
Description
This block optimizes a certain cost function using a nonlinear algorithm by varying the input values of a selected block. The inputs to the selected block will be optimized under certain constraints.
The selected block could be any Architect block that maps inputs to outputs, for example, a trained Nonlinear model. The selected block must also be in the same superblock as the Nonlinear Optimization block.
The cost function is an expressions which calculates a single cost value. The block will then search for the input values to the selected which will either minimise or maximise the output of the cost function. The cost function must be dependent on the output value of the selected block.
Constraints can be set on the input values to the selected block. Each field to the selected block can be configured to be one of the following:
-
Constant value: The field can be considered as a constant value. The constant value can either be a floating point value or a field selected from the Nonlinear Optimizations input port. If the constant value is a field, the value of the field will be used as the constant value at the time when the optimization was started.
-
Optimized value: The value must be optimized. The user set the range constraint in which the value must fall. [minimum .. maximum]. The precision of the search is another constraint that can be configured.
The trigger for when optimization will be started, will be set by selecting one of the input fields to the Nonlinear Optimization block. The block will monitor these fields and when any of the timestamps on these fields change, the block will start the optimization. The optimization will however not be started if any of the input fields to the Nonlinear Optimization block contain bad quality values.
The output of the Nonlinear Optimization block is the optimized input values.
DIAGRAM OF THE NonlineAR OPTIMIzATION BLOCK
Block Type
Rules and Models
Input/Output ports
The block contains one input port. This input port can contain any integer or double fields. None of the input field names to the Nonlinear Optimization block may start with ‘I_’ or ‘O_’ because the block uses these prefixes.
The OptimizedValues output port of the block will contain the results of the optimization. The output fields will have the same name and types as the input fields of the selected block. These values will be the best values that can be given to the selected block, to give the optimum (minimum or maximum) result of the cost function (as defined by the user).
The CostFunctionValues output port will contain the same fields as in the input port. When an optimization finishes, the block will place the values of the input fields (as they were when the optimization was started), into these fields. The only difference will be the timestamp which will be modified to have the same timestamp as the fields in the OptimizedValues output port.
Functions performed on tags
The OptimizedValues output port of the block will contain the same fields as the input port of the selected block being optimized.
-
The values placed in the OptimizedValues output port will be the best values that can be given to the selected block to give the optimum (minimum or maximum) result of the cost function. The value of the output stays unchanged if no new optimized result was found during the time from the previous execution till now.
-
The timestamp of the output fields will be the same as the execute timestamp of the Nonlinear Optimization block.
-
The block will contain bad quality values when there are no optimized results, otherwise it will be good. In the first execution the quality is bad.
The CostFunctionValues output port of the block will contain the same fields as the input port of the Nonlinear Optimization block. The value, quality and timestamp of these fields will only be updated when an optimization finishes with good results.
-
The values placed in these fields will be the same as the input values to the Nonlinear Optimization block at the time when the optimization was started.
-
The timestamps of these fields will be the same the execute timestamp of the Nonlinear Optimization block
-
The qualities of these fields will be set to good quality.
Example 1:
For example take a hypothetical block that takes two input fields X and Y. These fields are double values ranging from –3.0 to 3.0. The result the block gives in the output port is the output value Output. Output is calculated by:
Output = sin(X) + sin(Y).
Now to get the best values for X and Y to get the maximum output value for Output, we can use the Nonlinear Optimization block. Configure the Nonlinear Optimization block by setting the selected block to this hypothetical block. Then set the cost function as:
O_Output
The block then needs to be set to maximize the cost function. The minimum and maximum values for the inputs then needs to be configured on the Inputs tab, along with the precision.
In this case we don't use any of the input fields to the Nonlinear Optimization block, but the block still needs to be connected to the dataflow in the same superblock as our hypothetical block.
When the block then executes, it will use nonlinear algorithms to search for optimal X and Y values, so that the cost function (which in this case is just O_Output) is maximized.
Note: This hypothetical block can be created with a Nonlinear block that was trained on the correct data to mimic the behavior of the function Output = sin(X) + sin(Y).
Example 2:
Take the same block as in example 1. In this case we want to specify the output value we want the selected block to return. The Nonlinear Optimization block must search for the best values of X and Y that we can give as input to the selected block, so that the block will output a value as close as possible to output value we specified. This is done in the following manner.
In this case the input fields of the Nonlinear Optimization block can be used to define target values we want the selected block to give as output. We add a field to the input port of the Nonlinear Optimization block called TargetValue.
Now we want to find the best values for X and Y so that the Output field of the hypothetical block is as close as possible to TargetValue. In this case we define the cost function as
abs( O_Output – TargetValue )
We also set the Nonlinear Optimization block to minimize the cost function. The minimum, maximum and precision values for the inputs do not need to change.
When the block is now executed, the block will search for the smallest value of the cost function, by changing the values of X and Y based on a nonlinear algorithm. The block will then place the best values of X and Y in the output port of the Nonlinear Optimization block. These are the best values the block found, which can then be given as input to the selected block and which in turn will return a value close to the TargetValue.
Note: The above-mentioned cost function can be generated automatically with the Generate RMS cost function button on the blocks property page.
Related topics: