このページの翻訳は最新ではありません。ここをクリックして、英語の最新版を参照してください。
複数のシミュレーション シナリオを使用したデータ型の最適化
この例では、複数のシミュレーション シナリオを作成する方法、およびそのシナリオを使用してシステムの固定小数点データ型を最適化する方法を示します。
モデルを開きます。この例では、Controller サブシステムのデータ型を最適化します。モデルは、ランプ入力またはランダム入力のいずれかを使用するよう設定されています。モデルは、信号許容誤差を使用せずに、Assertion ブロックを使用して、固定小数点実装の数値的な動作を検証します。詳細については、動作の制約の指定を参照してください。
model = 'ex_controllerHarness';
open_system(model);
シミュレーション シナリオの作成
さまざまなシナリオを含む Simulink.SimulationInput
オブジェクトを作成します。ランプ入力と、4 つの異なる seed の両方をランダム入力に使用します。
si = Simulink.SimulationInput.empty(5, 0); % scan through 4 different seeds for the random input rng(1); seeds = randi(1e6, [1 4]); for sIndex = 1:length(seeds) si(sIndex) = Simulink.SimulationInput(model); si(sIndex) = si(sIndex).setVariable('SOURCE', 2); % SOURCE == 2 corresponds to the random input si(sIndex) = si(sIndex).setBlockParameter([model '/Random/uniformRandom'], 'Seed', num2str(seeds(sIndex))); % scan through the seeds si(sIndex) = si(sIndex).setUserString(sprintf('random_%i', seeds(sIndex))); end % setting SOURCE == 1 corresponds to the ramp input si(5) = Simulink.SimulationInput(model); si(5) = si(5).setVariable('SOURCE', 1); si(5) = si(5).setUserString('Ramp');
固定小数点最適化オプションの指定
反復回数や範囲収集のメソッドなどの最適化のオプションを指定するには、fxpOptimizationOptions
オブジェクトを使用します。この例では、派生された範囲解析を使用してシステムの範囲収集を行います。
options = fxpOptimizationOptions('MaxIterations', 3e2, 'Patience', 50); options.AdvancedOptions.PerformNeighborhoodSearch = false; % use derived range analysis for range collection options.AdvancedOptions.UseDerivedRangeAnalysis = true
options = fxpOptimizationOptions with properties: MaxIterations: 300 MaxTime: 600 Patience: 50 Verbosity: High AllowableWordLengths: [2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ... ] ObjectiveFunction: BitWidthSum UseParallel: 0 Advanced Options AdvancedOptions: [1x1 DataTypeOptimization.AdvancedFxpOptimizationOptions]
高度なオプションのシミュレーション シナリオとして、シミュレーション入力オブジェクトを指定します。
options.AdvancedOptions.SimulationScenarios = si;
最適化の実行と結果の確認
最適化中、ソフトウェアは、高度なオプションで指定されたすべてのシミュレーション シナリオの範囲を派生します。ソフトウェアは、各シミュレーション入力シナリオに対してソリューションを検証します。
result = fxpopt(model, [model '/Controller'], options)
+ Starting data type optimization... + Checking for unsupported constructs. + Preprocessing + Modeling the optimization problem - Constructing decision variables + Running the optimization solver - Evaluating new solution: cost 496, does not meet the behavioral constraints. - Evaluating new solution: cost 976, does not meet the behavioral constraints. - Evaluating new solution: cost 1936, meets the behavioral constraints. - Updated best found solution, cost: 1936 + Optimization has finished. + Fixed-point implementation that satisfies the behavioral constraints found. The best found solution is applied on the model. - Total cost: 1936 - Use the explore method of the result to explore the implementation. result = OptimizationResult with properties: Model: 'ex_controllerHarness' SystemUnderDesign: 'ex_controllerHarness/Controller' FinalOutcome: 'Fixed-point implementation that satisfies the behavioral constraints found. The best found solution is applied on the model.' OptimizationOptions: [1x1 fxpOptimizationOptions] Solutions: [1x1 DataTypeOptimization.OptimizationSolution]
各ソリューションを、定義した各シミュレーション シナリオと比較して確認できます。最もよく見つかったソリューションを調べ、それをランプ シミュレーション入力と共に表示します。このランプ入力はシミュレーション シナリオ 5 です。
solutionIndex = 1; % get the best found solution scenarioIndex = 5; % get the 5th scenario (ramp) solution = explore(result, solutionIndex, scenarioIndex);