Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/quasi-newton.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export AbstractDiagonalQNModel,
LSR1Model,
DiagonalPSBModel,
DiagonalAndreiModel,
DiagonalBFGSModel,
SpectralGradientModel,
get_model,
get_op
Expand Down Expand Up @@ -130,6 +131,23 @@ function DiagonalAndreiModel(
return DiagonalQNModel{T, S, typeof(nlp), typeof(nlp.meta), typeof(op)}(nlp.meta, nlp, op)
end

"""
DiagonalBFGSModel(nlp; d0 = fill!(S(undef, nlp.meta.nvar), 1.0))

Construct a `DiagonalBFGSModel` from another type of nlp, in which the Hessian is approximated
via a diagonal BFGS quasi-Newton operator.
`d0` is the initial approximation of the diagonal of the Hessian, and by default a vector of ones.
See the
[`DiagonalBFGS operator documentation`](https://juliasmoothoptimizers.github.io/LinearOperators.jl/stable/reference/#LinearOperators.DiagonalBFGS).
"""
function DiagonalBFGSModel(
nlp::AbstractNLPModel{T, S};
d0::S = fill!(S(undef, nlp.meta.nvar), one(T)),
) where {T, S}
op = DiagonalBFGS(d0)
return DiagonalQNModel{T, S, typeof(nlp), typeof(nlp.meta), typeof(op)}(nlp.meta, nlp, op)
end

"""
SpectralGradientModel(nlp; σ = 1.0)

Expand Down
12 changes: 10 additions & 2 deletions test/nlp/quasi-newton.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
(LBFGSModel, LBFGSOperator),
(DiagonalPSBModel, DiagonalPSB),
(DiagonalAndreiModel, DiagonalAndrei),
(DiagonalBFGSModel, DiagonalBFGS),
(SpectralGradientModel, SpectralGradient),
],
T in [Float64, Float32],
Expand All @@ -24,7 +25,7 @@
m = nlp.meta.ncon

s, y = randn(T, n), randn(T, n)
if QNO ∈ (DiagonalPSB, DiagonalAndrei)
if QNO ∈ (DiagonalPSB, DiagonalAndrei, DiagonalBFGS)
B = QNO(ones(T, n))
elseif QNO == SpectralGradient
B = QNO(one(T), n)
Expand Down Expand Up @@ -153,7 +154,14 @@
end

@testset "Show" begin
for QNM ∈ [LSR1Model, LBFGSModel, DiagonalPSBModel, DiagonalAndreiModel, SpectralGradientModel]
for QNM ∈ [
LSR1Model,
LBFGSModel,
DiagonalPSBModel,
DiagonalAndreiModel,
DiagonalBFGSModel,
SpectralGradientModel,
]
nlp = QNM(SimpleNLPModel())
io = IOBuffer()
show(io, nlp)
Expand Down
Loading