lesson 22/11, heavy ball method not translated yet

This commit is contained in:
elvis
2023-11-25 20:16:56 +01:00
parent b1c433832f
commit f36dec52dd
5 changed files with 3506 additions and 10 deletions

View File

@ -80,9 +80,8 @@ function NWTN(f;
if printing
@printf(" %2d", lsiter)
end
a = as;
a = as
return (a, phia) # Armijo + strong Wolfe satisfied, we are done
end
if phips 0
break
@ -272,7 +271,7 @@ function NWTN(f;
# output statistics - - - - - - - - - - - - - - - - - - - - - - - - - -
if fStar > -Inf
gapk = ( v - fStar ) / max(abs( fStar ), 1)
gapk = (v - fStar) / max(abs(fStar), 1)
if printing
@printf("%4d\t%1.4e\t%1.4e", feval, gapk, ng)

View File

@ -95,22 +95,22 @@ end
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function genericquad(Q, q, x::Union{Nothing, Real})
function genericquad(Q, q, x::Union{Nothing, AbstractVecOrMat})
# generic quadratic function f(x) = x' * Q * x / 2 + q' * x
if x === nothing # informative call
if minimum(eigvals(Q)) > 1e-14
xStar = Q \ -q
v = 0.5 * xStar' * Q * xStar + q' * xStar
v = 0.5 * dot(xStar, Q * xStar) + dot(q, xStar)
else
v = -Inf
end
return (v, zeros(size(q)), zeros(size(Q)))
else
if size(x) (2, 1)
if size(x, 1) 2 || size(x, 2) 1
throw(ArgumentError("genericquad: x is of wrong size"))
end
v = 0.5 * x' * Q * x + q' * x # f(x)
v = 0.5 * dot(x, Q * x) + dot(q, x) # f(x)
return (v, Q * x + q, Q)
end
end # genericquad