-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using LinearOperators | ||
|
||
export QuasiNewtonModel, LBFGSModel, LSR1Model, | ||
reset!, | ||
obj, grad, grad!, | ||
cons, cons!, jac_coord, jac, jprod, jprod!, jtprod, jtprod!, | ||
hess, hprod | ||
|
||
abstract QuasiNewtonModel <: AbstractNLPModel | ||
|
||
type LBFGSModel <: QuasiNewtonModel | ||
meta :: NLPModelMeta | ||
model :: AbstractNLPModel | ||
op :: LBFGSOperator | ||
end | ||
|
||
type LSR1Model <: QuasiNewtonModel | ||
meta :: NLPModelMeta | ||
model :: AbstractNLPModel | ||
op :: LSR1Operator | ||
end | ||
|
||
"Construct a `LBFGSModel` from another type of model." | ||
function LBFGSModel(nlp :: AbstractNLPModel; memory :: Int=5) | ||
op = LBFGSOperator(nlp.meta.nvar, memory) | ||
return LBFGSModel(nlp.meta, nlp, op) | ||
end | ||
|
||
"Construct a `LSR1Model` from another type of nlp." | ||
function LSR1Model(nlp :: AbstractNLPModel; memory :: Int=5) | ||
op = LSR1Operator(nlp.meta.nvar, memory) | ||
return LSR1Model(nlp.meta, nlp, op) | ||
end | ||
|
||
# retrieve counters from underlying model | ||
for counter in fieldnames(Counters) | ||
@eval begin | ||
$counter(nlp :: QuasiNewtonModel) = $counter(nlp.model) | ||
export $counter | ||
end | ||
end | ||
|
||
function reset!(nlp :: QuasiNewtonModel) | ||
reset!(nlp.model.counters) | ||
return nlp | ||
end | ||
|
||
# the following methods are not affected by the Hessian approximation | ||
for meth in (:obj, :grad, :grad!, :cons, :cons!, :jac_coord, :jac, :jprod, :jprod!, :jtprod, :jtprod!) | ||
@eval begin | ||
$meth(nlp :: QuasiNewtonModel, args...) = $meth(nlp.model, args...) | ||
end | ||
end | ||
|
||
# the following methods are affected by the Hessian approximation | ||
hess_op(nlp :: QuasiNewtonModel, args...) = nlp.op | ||
hprod(nlp :: QuasiNewtonModel, x :: Array{Float64}, v :: Array{Float64}; kwargs...) = nlp.op * v | ||
|
||
function update!(nlp :: QuasiNewtonModel, args...) | ||
nlp.op.push!(args...) | ||
return nlp | ||
end | ||
|
||
# not implemented: hess_coord, hess, hprod! |