starting vector (zero vector) equals lower bounds but gets projected to non-zero vector
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
SA-W
am 8 Okt. 2024
Bearbeitet: Bruno Luong
am 11 Okt. 2024
I created a small example where I created a start vector euqal to the lower bounds, so the start vector respects the bounds, thought gets projected to non-zero vector when double-checking inside objective function.
Is this a bug or do I miss something here?
n = 5;
lb = zeros(n,1);
ub = Inf(5, 1);
startVec = zeros(n, 1);
sol = fmincon(@(x)func(x), startVec, [], [], [], [], lb, ub);
function fval = func(x)
% start vector (zero vector) becomes [0.99 0.99 0.99 0.99 0.99]
if any(x ~= 0)
error('Unexpected values: x is not the zero vector. Current x: %s', num2str(x'));
end
end
4 Kommentare
Bruno Luong
am 10 Okt. 2024
Bearbeitet: Bruno Luong
am 10 Okt. 2024
It does what it does, user should not want to interfer with the optimizer while it is working. Only the final end result it returns count.
Pratically any numerical floating point comparison implementation outthere work with some sort of tolerance, each decides the tolerance to be resonable (based on the estimate scale of your data) in practice. The scale estimation is often empirical, and more like an art than precice math, we just have to accept it.
So far your question does not show anything wrong or bug with FMINCON as far as I can see it.
Bruno Luong
am 11 Okt. 2024
Bearbeitet: Bruno Luong
am 11 Okt. 2024
More interesting observation is that the there is always a strict positive tolerance to the constraints on interior point algorithm. Code based on Matt's demo show that in the final solution
n = 5;
lb = zeros(n,1);
ub = Inf(n,1);
startVec = ones(n,1);
opts = optimoptions('fmincon','Algorithm','sqp');
sol = fmincon(@func, startVec, [], [], [], [], lb, ub, [], opts)
opts = optimoptions('fmincon','Algorithm','interior-point');
sol = fmincon(@func, startVec, [], [], [], [], lb, ub, [], opts)
function fval = func(x)
fval = sum((x+1).^2);
end
Akzeptierte Antwort
Walter Roberson
am 8 Okt. 2024
Although the documentation says that lb specifies that x(i) >= lb(i) for all i the implementing code has
violatedLowerBnds_idx = XOUT(xIndices.finiteLb) <= l(xIndices.finiteLb);
and when true, shifts the bounds away from the starting point.
Notice the <= in the test -- so an input vector that is exactly equal to the lower bounds is considered to be in violation of the bounds.
This is arguably a bug in the implementation.
10 Kommentare
Weitere Antworten (1)
Matt J
am 10 Okt. 2024
Bearbeitet: Matt J
am 10 Okt. 2024
This behavior is specific to the interior-point algorithm. As the name suggests, an interior-point algorithm must start at an interior point.
Demo('sqp')
Demo('interior-point')
function Demo(alg)
n = 5;
lb = zeros(n,1);
ub = Inf(5, 1);
startVec = zeros(n, 1);
FirstCall=true;
opts=optimoptions('fmincon','Algorithm',alg);
sol = fmincon(@func, startVec, [], [], [], [], lb, ub,[],opts)
function fval = func(x)
if any(x ~= 0) && FirstCall
error('Unexpected values: x is not the zero vector. Current x: %s', num2str(x'));
else
fval=norm(x-1)^2; FirstCall=false;
end
end
end
2 Kommentare
Bruno Luong
am 10 Okt. 2024
Bearbeitet: Bruno Luong
am 11 Okt. 2024
Yes exactly, it's even describeb in the doc where I hightlighted the relevant paragraphe here
Siehe auch
Kategorien
Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!