このページは機械翻訳を使用して翻訳されました。最新版の英語を参照するには、ここをクリックします。
surrogateoptを使用した最適なコンポーネントの選択
この例では、回路内の 1 つのポイントで指定された曲線に最適に一致するように回路内の抵抗器とサーミスタを選択する方法を示します。利用可能なコンポーネントのリストからすべての電子コンポーネントを選択する必要があるため、これは離散最適化問題です。最適化の進行状況を視覚的に確認できるように、この例には、最適化の進行に合わせて中間ソリューションの品質を表示するカスタム出力関数が含まれています。これは非線形目的関数を持つ整数問題なので、surrogateopt ソルバーを使用します。
この例はリヨン[1]から改変したものである。
問題の説明
問題はこの回路に関係しています。

電圧源はポイント A を 1.1V に保持します。問題は、ポイント B の電圧が温度の関数としての目標曲線と一致するように、標準コンポーネントのリストから抵抗器とサーミスタを選択することです。
Tdata = -40:5:85; Vdata = 1.026E-1 + -1.125E-4 * Tdata + 1.125E-5 * Tdata.^2; plot(Tdata,Vdata,'-*'); title('Target Curve','FontSize',12); xlabel('Temperature (^oC)'); ylabel('Voltage (V)')

標準コンポーネント リストを読み込みます。
load StandardComponentValuesRes ベクトルには標準抵抗値が含まれています。ThBeta および ThVal ベクトルには、サーミスタの標準パラメーターが含まれています。サーミスタ抵抗の温度関数は
はサーミスタ抵抗です。
は 25 ℃ での抵抗、パラメーター
ThValです。は気温 25 度です。
は現在の温度です。
はサーミスタパラメーター
ThBetaです。
標準電圧計算に基づくと、ブロックの抵抗の等価直列抵抗値は
,
そしてブロックの等価抵抗は
.
したがって、B点の電圧は
.
問題をコードに変換する
問題は、電圧 が目標曲線に最もよく一致するように、抵抗器 から とサーミスタ および を選択することです。制御変数 x が次の値を表すようにします。
x(i)= のインデックス、iは 1 から 4 までx(5)= のインデックスx(6)= のインデックス
tempCompCurve 関数は、結果の電圧を x と温度 Tdata に基づいて計算します。
type tempCompCurvefunction F = tempCompCurve(x,Tdata) %% Calculate Temperature Curve given Resistor and Thermistor Values % Copyright (c) 2012-2019, MathWorks, Inc. %% Input voltage Vin = 1.1; %% Thermistor Calculations % Values in x: R1 R2 R3 R4 RTH1(T_25degc) Beta1 RTH2(T_25degc) Beta2 % Thermistors are represented by: % Room temperature is 25degc: T_25 % Standard value is at 25degc: RTHx_25 % RTHx is the thermistor resistance at various temperatures % RTH(T) = RTH(T_25degc) / exp (Beta * (T-T_25)/(T*T_25)) T_25 = 298.15; T_off = 273.15; Beta1 = x(6); Beta2 = x(8); RTH1 = x(5) ./ exp(Beta1 * ((Tdata+T_off)-T_25)./((Tdata+T_off)*T_25)); RTH2 = x(7) ./ exp(Beta2 * ((Tdata+T_off)-T_25)./((Tdata+T_off)*T_25)); %% Define equivalent circuits for parallel Rs and RTHs R1_eq = x(1)*RTH1./(x(1)+RTH1); R3_eq = x(3)*RTH2./(x(3)+RTH2); %% Calculate voltages at Point B F = Vin * (R3_eq + x(4))./(R1_eq + x(2) + R3_eq + x(4));
目的関数は、目標温度範囲における、抵抗器とサーミスタのセットの目標曲線と結果として生じる電圧の差の二乗の合計です。
type objectiveFunctionfunction G = objectiveFunction(x,StdRes, StdTherm_Val, StdTherm_Beta,Tdata,Vdata) %% Objective function for the thermistor problem % Copyright (c) 2012-2019, MathWorks, Inc. % % StdRes = vector of resistor values % StdTherm_val = vector of nominal thermistor resistances % StdTherm_Beta = vector of thermistor temperature coefficients % Extract component values from tables using integers in x as indices y = zeros(8,1); x = round(x); % in case of noninteger components y(1) = StdRes(x(1)); y(2) = StdRes(x(2)); y(3) = StdRes(x(3)); y(4) = StdRes(x(4)); y(5) = StdTherm_Val(x(5)); y(6) = StdTherm_Beta(x(5)); y(7) = StdTherm_Val(x(6)); y(8) = StdTherm_Beta(x(6)); % Calculate temperature curve for a particular set of components F = tempCompCurve(y, Tdata); % Compare simulated results to target curve Residual = F(:) - Vdata(:); Residual = Residual(1:2:26); %% G = Residual'*Residual; % sum of squares
進行状況の監視
最適化の進行状況を観察するには、これまでに見つかったシステムの最適な応答とターゲット曲線をプロットする出力関数を呼び出します。SurrOptimPlot 関数はこれらの曲線をプロットし、現在の目的関数の値が減少した場合にのみ曲線を更新します。このカスタム出力関数は長いため、ここでは示されていません。この出力関数の内容を表示するには、「type SurrOptimPlot」と入力します。
最適化問題
目的関数を最適化するには、整数変数を受け入れる surrogateopt を使用します。まず、すべての変数を整数に設定します。
intCon = 1:6;
すべての変数の下限を 1 に設定します。
lb = ones(1,6);
抵抗器の上限はすべて同じです。上限を Res データのエントリ数に設定します。
ub = length(Res)*ones(1,6);
サーミスタの上限を ThBeta データのエントリ数に設定します。
ub(5:6) = length(ThBeta)*[1,1];
SurrOptimPlot カスタム出力関数を使用し、プロット関数を使用しないオプションを設定します。また、最適化の中断を防ぐために、'checkfile.mat' という名前のチェックポイント ファイルを指定します。
options = optimoptions('surrogateopt','CheckpointFile','C:\TEMP\checkfile.mat','PlotFcn',[],... 'OutputFcn',@(a1,a2,a3)SurrOptimPlot(a1,a2,a3,Tdata,Vdata,Res,ThVal,ThBeta));
アルゴリズムに探索するポイントの初期セットをより適切に提供するには、デフォルトよりも大きな初期ランダム サンプルを指定します。
options.MinSurrogatePoints = 50;
最適化を実行します。
rng default % For reproducibility objconstr = @(x)objectiveFunction(x,Res,ThVal,ThBeta,Tdata,Vdata); [xOpt,Fval] = surrogateopt(objconstr,lb,ub,intCon,options);

surrogateopt stopped because it exceeded the function evaluation limit set by 'options.MaxFunctionEvaluations'.
より多くの関数評価による最適化
より良い適合を得るには、チェックポイント ファイルから最適化を再開し、より多くの関数評価を指定します。今回は、surrogateoptplot プロット関数を使用して、最適化プロセスをより詳しく監視します。
clf % Clear previous figure opts = optimoptions(options,'MaxFunctionEvaluations',600,'PlotFcn','surrogateoptplot'); [xOpt,Fval] = surrogateopt('C:\TEMP\checkfile.mat',opts);


surrogateopt stopped because it exceeded the function evaluation limit set by 'options.MaxFunctionEvaluations'.
関数評価をさらに使用すると、適合性がわずかに向上します。
参考文献
[1] Lyon, Craig K. Genetic algorithm solves thermistor-network component values.EDN Network, March 19, 2008.https://www.edn.com/genetic-algorithm-solves-thermistor-network-component-values/ から入手可能。