Optimize data types of a system
result = fxpopt(model, sud, options)
This example shows how to optimize the data types used by a system based on specified tolerances.
To begin, open the system for which you want to optimize the data types.
model ='ex_auto_gain_controller'; sud ='ex_auto_gain_controller/sud'; open_system(model)
Create anfxpOptimizationOptions
object to define constraints and tolerances to meet your design goals.
opt = fxpOptimizationOptions()
opt = fxpOptimizationOptions with properties: MaxIterations: 50 MaxTime: 600 Patience: 10 Verbosity: High AllowableWordLengths: [1x128 double] Advanced Options AdvancedOptions: [1x1 struct]
Use theaddTolerance
method to define tolerances for the differences between the original behavior of the system, and the behavior using the optimized fixed-point data types. You can also specify word lengths to allow in your design.
tol = 10e-2; addTolerance(opt, [model'/output_signal'], 1,'AbsTol', tol); opt.AllowableWordLengths = 10:24;
Use thefxpopt
function to run the optimization. The software analyzes ranges of objects in your system under design and the constraints specified in thefxpOptimizationOptions
object to apply heterogeneous data types to your system while minimizing total bit width.
result = fxpopt(model, sud, opt);
+预处理 +建模优化问题 - 构建决策变量 - 绑定约束 +运行优化求解器 - 评估新解决方案:成本180,不符合公差。- 评估新解决方案:成本198,不符合公差。- 评估新解决方案:成本216,不符合公差。- 评估新解决方案:成本234,不符合公差。- 评估新解决方案:成本252,不符合公差。- 评估新解决方案:成本270,不符合公差。- 评估新解决方案:成本288,不符合公差。- 评估新解决方案:成本306,满足公差。- 最新发现的解决方案,成本:306-评估新解决方案:成本304,满足公差。- 最新发现的解决方案,成本:304-评估新解决方案:成本300,满足公差。 - Updated best found solution, cost: 300 - Evaluating new solution: cost 299, meets the tolerances. - Updated best found solution, cost: 299 - Evaluating new solution: cost 298, meets the tolerances. - Updated best found solution, cost: 298 - Evaluating new solution: cost 297, meets the tolerances. - Updated best found solution, cost: 297 - Evaluating new solution: cost 296, meets the tolerances. - Updated best found solution, cost: 296 - Evaluating new solution: cost 295, meets the tolerances. - Updated best found solution, cost: 295 - Evaluating new solution: cost 294, does not meet the tolerances. - Evaluating new solution: cost 293, meets the tolerances. - Updated best found solution, cost: 293 - Evaluating new solution: cost 292, meets the tolerances. - Updated best found solution, cost: 292 - Evaluating new solution: cost 291, meets the tolerances. - Updated best found solution, cost: 291 - Evaluating new solution: cost 290, meets the tolerances. - Updated best found solution, cost: 290 - Evaluating new solution: cost 289, meets the tolerances. - Updated best found solution, cost: 289 - Evaluating new solution: cost 287, meets the tolerances. - Updated best found solution, cost: 287 - Evaluating new solution: cost 283, meets the tolerances. - Updated best found solution, cost: 283 - Evaluating new solution: cost 282, meets the tolerances. - Updated best found solution, cost: 282 - Evaluating new solution: cost 281, meets the tolerances. - Updated best found solution, cost: 281 - Evaluating new solution: cost 280, meets the tolerances. - Updated best found solution, cost: 280 - Evaluating new solution: cost 279, meets the tolerances. - Updated best found solution, cost: 279 - Evaluating new solution: cost 278, meets the tolerances. - Updated best found solution, cost: 278 - Evaluating new solution: cost 277, does not meet the tolerances. - Evaluating new solution: cost 276, meets the tolerances. - Updated best found solution, cost: 276 - Evaluating new solution: cost 275, meets the tolerances. - Updated best found solution, cost: 275 - Evaluating new solution: cost 274, meets the tolerances. - Updated best found solution, cost: 274 - Evaluating new solution: cost 273, meets the tolerances. - Updated best found solution, cost: 273 - Evaluating new solution: cost 272, meets the tolerances. - Updated best found solution, cost: 272 - Evaluating new solution: cost 270, meets the tolerances. - Updated best found solution, cost: 270 - Evaluating new solution: cost 266, meets the tolerances. - Updated best found solution, cost: 266 - Evaluating new solution: cost 265, meets the tolerances. - Updated best found solution, cost: 265 - Evaluating new solution: cost 264, meets the tolerances. - Updated best found solution, cost: 264 - Evaluating new solution: cost 263, meets the tolerances. - Updated best found solution, cost: 263 - Evaluating new solution: cost 262, meets the tolerances. - Updated best found solution, cost: 262 - Evaluating new solution: cost 261, meets the tolerances. - Updated best found solution, cost: 261 - Evaluating new solution: cost 260, does not meet the tolerances. - Evaluating new solution: cost 259, does not meet the tolerances. - Evaluating new solution: cost 260, meets the tolerances. - Updated best found solution, cost: 260 - Evaluating new solution: cost 259, meets the tolerances. - Updated best found solution, cost: 259 - Evaluating new solution: cost 258, meets the tolerances. - Updated best found solution, cost: 258 - Evaluating new solution: cost 257, meets the tolerances. - Updated best found solution, cost: 257 - Evaluating new solution: cost 255, meets the tolerances. - Updated best found solution, cost: 255 - Evaluating new solution: cost 251, meets the tolerances. - Updated best found solution, cost: 251 - Evaluating new solution: cost 250, meets the tolerances. - Updated best found solution, cost: 250 - Evaluating new solution: cost 249, meets the tolerances. - Updated best found solution, cost: 249 - Evaluating new solution: cost 248, meets the tolerances. - Updated best found solution, cost: 248 - Evaluating new solution: cost 247, meets the tolerances. - Updated best found solution, cost: 247 - Evaluating new solution: cost 246, meets the tolerances. - Updated best found solution, cost: 246 - Evaluating new solution: cost 245, does not meet the tolerances. - Evaluating new solution: cost 244, does not meet the tolerances. - Evaluating new solution: cost 245, meets the tolerances. - Updated best found solution, cost: 245 - Evaluating new solution: cost 244, meets the tolerances. - Updated best found solution, cost: 244 + Optimization has finished. - Neighborhood search complete. + Fixed-point implementation that met the tolerances found. - Total cost: 244 - Maximum absolute difference: 0.077478 - Use the explore method of the result to explore the implementation.
Use the explore method of theOptimizationResult
object,result
, to launch Simulation Data Inspector and explore the design containing the smallest total number of bits while maintaining the numeric tolerances specified in theopt
object.
explore(result);
model
—模型包含系统设计,sud
Name of the model containing the system that you want to optimize.
数据类型:char
sud
—Model or subsystem whose data types you want to optimizeModel or subsystem whose data types you want to optimize, specified as a character vector containing the path to the system.
数据类型:char
options
—Additional optimization optionsfxpOptimizationOptions
objectfxpOptimizationOptions
object specifying additional options to use during the data type optimization process.
result
— Object containing the optimized designOptimizationResult
objectResult of the optimization, returned as anOptimizationResult
object. Use theexplore
method of the object to open the Simulation Data Inspector and view the behavior of the optimized system. You can also explore other solutions found during the optimization that may or may not meet the constraints specified in thefxpOptimizationOptions
object,options
.
You clicked a link that corresponds to this MATLAB command:
运行该命令,进入它MATLAB Command Window. Web browsers do not support MATLAB commands.
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:.
Selectweb siteYou can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.