Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
dynare
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dynare
dynare
Commits
371fdb22
Commit
371fdb22
authored
Jan 22, 2021
by
Johannes Pfeifer
Browse files
Options
Downloads
Patches
Plain Diff
solvopt.m: use gradient as second output instead of expecting separate function
parent
78a4bca3
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!1809
Prepare solve_opt for analytic gradients
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
matlab/optimization/solvopt.m
+23
-19
23 additions, 19 deletions
matlab/optimization/solvopt.m
with
23 additions
and
19 deletions
matlab/optimization/solvopt.m
+
23
−
19
View file @
371fdb22
...
...
@@ -14,9 +14,8 @@ function [x,f,exitflag,n_f_evals,n_grad_evals,n_constraint_evals,n_constraint_gr
%
fun
name
of
an
M
-
file
(
M
-
function
)
which
computes
the
value
%
of
the
objective
function
<
fun
>
at
a
point
x
,
%
synopsis
:
f
=
fun
(
x
)
%
grad
name
of
an
M
-
file
(
M
-
function
)
which
comput
es
the
gradient
%
grad
indicator
whether
objective
function
provid
es
the
gradient
%
vector
of
the
function
<
fun
>
at
a
point
x
,
%
synopsis
:
g
=
grad
(
x
)
%
func
name
of
an
M
-
file
(
M
-
function
)
which
computes
the
MAXIMAL
%
RESIDUAL
(
!
)
for
a
set
of
constraints
at
a
point
x
,
%
synopsis
:
fc
=
func
(
x
)
...
...
@@ -126,7 +125,7 @@ if nargin<2 % Function and/or starting point are not specified
end
if nargin<3
app=1; % No user-supplied gradients
elseif isempty(grad)
elseif isempty(grad)
|| grad==0
app=1;
else
app=0; % Exact gradients are supplied
...
...
@@ -271,9 +270,19 @@ stopf=0;
% COMPUTE THE FUNCTION ( FIRST TIME ) ----{
if trx
if app
f=feval(fun,x',varargin{:});
else
[f,g]=feval(fun,x',varargin{:});
n_grad_evals=n_grad_evals+1;
end
else
if app
f=feval(fun,x,varargin{:});
else
[f,g]=feval(fun,x,varargin{:});
n_grad_evals=n_grad_evals+1;
end
end
n_f_evals=n_f_evals+1;
if isempty(f)
...
...
@@ -378,12 +387,7 @@ if app
end
n_f_evals=n_f_evals+n;
else
if trx
g=feval(grad,x',varargin{:});
else
g=feval(grad,x,varargin{:});
end
n_grad_evals=n_grad_evals+1;
%done above
end
if size(g,2)==1, g=g'; end
ng=norm(g);
...
...
@@ -787,9 +791,9 @@ while 1
n_f_evals=n_f_evals+n;
else
if trx
g
=feval(
grad
,x',varargin{:});
[~,g]
=feval(
fun
,x',varargin{:});
else
g
=feval(
grad
,x,varargin{:});
[~,g]
=feval(
fun
,x,varargin{:});
end
n_grad_evals=n_grad_evals+1;
end
...
...
@@ -1084,7 +1088,7 @@ while 1
elseif isnan(f)
if dispwarn
disp(errmes)
disp(error3
2
)
disp(error3
1
)
end
exitflag=-3;
if trx
...
...
@@ -1105,9 +1109,9 @@ while 1
n_f_evals=n_f_evals+n;
else
if trx
g
=feval(
grad
,x',varargin{:});
[~,g]
=feval(
fun
,x',varargin{:});
else
g
=feval(
grad
,x,varargin{:});
[~,g]
=feval(
fun
,x,varargin{:});
end
n_grad_evals=n_grad_evals+1;
end
...
...
@@ -1210,9 +1214,9 @@ while 1
n_f_evals=n_f_evals+n;
else
if trx
gt=feval(
grad
,x1',varargin{:});
[~,
gt
]
=feval(
fun
,x1',varargin{:});
else
gt=feval(
grad
,x1,varargin{:});
[~,
gt
]
=feval(
fun
,x1,varargin{:});
end
n_grad_evals=n_grad_evals+1;
end
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment