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
dfa6359d
Verified
Commit
dfa6359d
authored
4 years ago
by
Sébastien Villemot
Browse files
Options
Downloads
Plain Diff
Merge branch 'solve_opt' of git.dynare.org:JohannesPfeifer/dynare
parents
565d61aa
a89f21b5
No related branches found
No related tags found
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
+26
-19
26 additions, 19 deletions
matlab/optimization/solvopt.m
with
26 additions
and
19 deletions
matlab/optimization/solvopt.m
+
26
−
19
View file @
dfa6359d
...
@@ -14,9 +14,8 @@ function [x,f,exitflag,n_f_evals,n_grad_evals,n_constraint_evals,n_constraint_gr
...
@@ -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
%
fun
name
of
an
M
-
file
(
M
-
function
)
which
computes
the
value
%
of
the
objective
function
<
fun
>
at
a
point
x
,
%
of
the
objective
function
<
fun
>
at
a
point
x
,
%
synopsis
:
f
=
fun
(
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
,
%
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
%
func
name
of
an
M
-
file
(
M
-
function
)
which
computes
the
MAXIMAL
%
RESIDUAL
(
!
)
for
a
set
of
constraints
at
a
point
x
,
%
RESIDUAL
(
!
)
for
a
set
of
constraints
at
a
point
x
,
%
synopsis
:
fc
=
func
(
x
)
%
synopsis
:
fc
=
func
(
x
)
...
@@ -126,7 +125,7 @@ if nargin<2 % Function and/or starting point are not specified
...
@@ -126,7 +125,7 @@ if nargin<2 % Function and/or starting point are not specified
end
end
if nargin<3
if nargin<3
app=1; % No user-supplied gradients
app=1; % No user-supplied gradients
elseif isempty(grad)
elseif isempty(grad)
|| grad==0
app=1;
app=1;
else
else
app=0; % Exact gradients are supplied
app=0; % Exact gradients are supplied
...
@@ -271,9 +270,19 @@ stopf=0;
...
@@ -271,9 +270,19 @@ stopf=0;
% COMPUTE THE FUNCTION ( FIRST TIME ) ----{
% COMPUTE THE FUNCTION ( FIRST TIME ) ----{
if trx
if trx
if app
f=feval(fun,x',varargin{:});
f=feval(fun,x',varargin{:});
else
else
[f,g]=feval(fun,x',varargin{:});
n_grad_evals=n_grad_evals+1;
end
else
if app
f=feval(fun,x,varargin{:});
f=feval(fun,x,varargin{:});
else
[f,g]=feval(fun,x,varargin{:});
n_grad_evals=n_grad_evals+1;
end
end
end
n_f_evals=n_f_evals+1;
n_f_evals=n_f_evals+1;
if isempty(f)
if isempty(f)
...
@@ -378,12 +387,7 @@ if app
...
@@ -378,12 +387,7 @@ if app
end
end
n_f_evals=n_f_evals+n;
n_f_evals=n_f_evals+n;
else
else
if trx
%done above
g=feval(grad,x',varargin{:});
else
g=feval(grad,x,varargin{:});
end
n_grad_evals=n_grad_evals+1;
end
end
if size(g,2)==1, g=g'; end
if size(g,2)==1, g=g'; end
ng=norm(g);
ng=norm(g);
...
@@ -674,6 +678,9 @@ while 1
...
@@ -674,6 +678,9 @@ while 1
end
end
if ksm || kc>=mxtc
if ksm || kc>=mxtc
exitflag=-3;
exitflag=-3;
% don't return with NaN or Inf despite error code
x=x1;
f=f1;
if trx
if trx
x=x';
x=x';
end
end
...
@@ -787,9 +794,9 @@ while 1
...
@@ -787,9 +794,9 @@ while 1
n_f_evals=n_f_evals+n;
n_f_evals=n_f_evals+n;
else
else
if trx
if trx
g
=feval(
grad
,x',varargin{:});
[~,g]
=feval(
fun
,x',varargin{:});
else
else
g
=feval(
grad
,x,varargin{:});
[~,g]
=feval(
fun
,x,varargin{:});
end
end
n_grad_evals=n_grad_evals+1;
n_grad_evals=n_grad_evals+1;
end
end
...
@@ -1084,7 +1091,7 @@ while 1
...
@@ -1084,7 +1091,7 @@ while 1
elseif isnan(f)
elseif isnan(f)
if dispwarn
if dispwarn
disp(errmes)
disp(errmes)
disp(error3
2
)
disp(error3
1
)
end
end
exitflag=-3;
exitflag=-3;
if trx
if trx
...
@@ -1105,9 +1112,9 @@ while 1
...
@@ -1105,9 +1112,9 @@ while 1
n_f_evals=n_f_evals+n;
n_f_evals=n_f_evals+n;
else
else
if trx
if trx
g
=feval(
grad
,x',varargin{:});
[~,g]
=feval(
fun
,x',varargin{:});
else
else
g
=feval(
grad
,x,varargin{:});
[~,g]
=feval(
fun
,x,varargin{:});
end
end
n_grad_evals=n_grad_evals+1;
n_grad_evals=n_grad_evals+1;
end
end
...
@@ -1210,9 +1217,9 @@ while 1
...
@@ -1210,9 +1217,9 @@ while 1
n_f_evals=n_f_evals+n;
n_f_evals=n_f_evals+n;
else
else
if trx
if trx
gt=feval(
grad
,x1',varargin{:});
[~,
gt
]
=feval(
fun
,x1',varargin{:});
else
else
gt=feval(
grad
,x1,varargin{:});
[~,
gt
]
=feval(
fun
,x1,varargin{:});
end
end
n_grad_evals=n_grad_evals+1;
n_grad_evals=n_grad_evals+1;
end
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