陳宥廷 DextinWed, Oct 14, 2020
筆記
來自我修最佳設計時(2018)的作業5,當時發現fmincon決定計算機率的梯度,在作業中已經提出解法。
另外針對FOSM處理非線性問題,當初作業6中使用更好的修正方案,但還是無法解決根本問題,其實在作業4的結尾我有想到可能的解決方法,但當時沒有深入研究,最近忽然想到解決方法,想和大家分享。
利用隨機撒點來模擬真實系統的不確定性
以下是估算
n = 10000;
x = rand(n,1);
y = rand(n,1);
pi_e = 4*sum([x.^2 + y.^2] <= 1)/n;
% pi = 4倍面積機率
Learn More →
Learn More →
Learn More →
Learn More →
function [xsol, history, flag]=solve(x0)
lb = [0.01 0.01];
ub = [10 10];
options = optimoptions(@fmincon, 'OutputFcn', @outfun, 'Display', 'off');
[xsol, ~, flag] = fmincon(@(x) x(1)+x(2), x0, [], [], [], [], lb, ub, @nonlcon, options);
function stop = outfun(x,optimValues,state)
stop = false;
if state == 'iter'
history = [history; x optimValues.fval];
end
end
function [g, geq]=nonlcon(x)
g1 = 20 - x(2).*(x(1).^2);
g2 = 120 - 4*((x(1)+x(2)-5).^2) - (x(1)-x(2)-12).^2;
g3 = x(1).^2 + 8*x(2) - 75;
g = [g1 g2 g3];
geq = [];
end
end
給定
如果只按照新的限制條件來寫,會出現如下圖的情形,無法收斂到理想的位置
function [g, geq]=nonlcon(x)
n = 1e4; % 採樣數量
std = 0.3;
tolerance = 0.0013;
X1 = normrnd(x(1), std, [n, 1]);
X2 = normrnd(x(2), std, [n, 1]);
g1 = 20 - X2.*(X1.^2);
g2 = 120 - 4*((X1+X2-5).^2) - (X1-X2-12).^2;
g3 = X1.^2 + 8*X2 - 75;
g = [sum(g1>0); sum(g2>0); sum(g3>0)] - tolerance*n;
geq = [];
end
因為fmincon無法計算機率的梯度,因為機率、統計或布林函數只能計算符合或不符合的程度,其值無法有效表示當前位置,也無法計算梯度。
Learn More →
Learn More →
等價性
function [g, geq]=nonlcon(x)
ith = fix(n*0.0013) + 1;
g1 = 20 - X2.*(X1.^2);
g2 = 120 - 4*((X1+X2-5).^2) - (X1-X2-12).^2;
g3 = X1.^2 + 8*X2 - 75;
g = sort([g1 g2 g3],'descend');
g = g(ith,:);
% 取第ith大的作為代表
geq = [];
end
預先處理
條件與假設
[name=陳宥廷 Dextin][time=Sat, Mar 3, 2021] [color=#87CEFA] ➤ TeX Live安裝 前情提要 筆者使用的電腦是win10作業系統 已裝有VS Code MikTex和TeX Live大同小異,擇一安裝即可 Step 1:下載
Apr 10, 2021[name=陳宥廷 Dextin][time=Mon, Jun 20, 2020] [color=#87CEFA] PAGE是提供python可以方便開發GUI的tcl腳本,類似C#可以drag and drop的方式設計GUI外觀與編輯參數,但目前無法自動生成事件(至少筆者還不會XD) 官方網站 PAGE - Python Automatic GUI Generato 範例影片 {%youtube oULe0h0Jl3g%}
Apr 10, 2021or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up