Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
Dynare.jl
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Camilo Marchesini
Dynare.jl
Commits
05e3ad78
Commit
05e3ad78
authored
7 years ago
by
Stéphane Adjemian
Browse files
Options
Downloads
Patches
Plain Diff
Added basic linesearch learning over newton iterations.
Reduces significantly the number of iterations.
parent
16edf443
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/DynareSolvers.jl
+23
-4
23 additions, 4 deletions
src/DynareSolvers.jl
with
23 additions
and
4 deletions
src/DynareSolvers.jl
+
23
−
4
View file @
05e3ad78
...
@@ -179,9 +179,10 @@ function trustregion(f!::Function, j!::Function, x0::Vector{Float64}, factor::Fl
...
@@ -179,9 +179,10 @@ function trustregion(f!::Function, j!::Function, x0::Vector{Float64}, factor::Fl
catch
catch
error
(
"The Jacobian of the system of nonlinear equations cannot be evaluated on the initial guess!"
)
error
(
"The Jacobian of the system of nonlinear equations cannot be evaluated on the initial guess!"
)
end
end
# Initialize counters
# Initialize counters.
ncsucc
=
zero
(
Int
)
ncsucc
,
nslow1
=
zero
(
Int
),
zero
(
Int
)
nslow1
=
zero
(
Int
)
# Initialize scale parameter.
scale
,
scale0
=
one
(
Float64
),
one
(
Float64
)
# Newton iterations
# Newton iterations
while
iter
<=
maxiter
&&
info
==
0
while
iter
<=
maxiter
&&
info
==
0
# Compute columns norm for the Jacobian matrix.
# Compute columns norm for the Jacobian matrix.
...
@@ -224,7 +225,7 @@ function trustregion(f!::Function, j!::Function, x0::Vector{Float64}, factor::Fl
...
@@ -224,7 +225,7 @@ function trustregion(f!::Function, j!::Function, x0::Vector{Float64}, factor::Fl
if
iter
==
1
if
iter
==
1
δ
=
min
(
δ
,
pnorm
)
δ
=
min
(
δ
,
pnorm
)
end
end
fwrong
,
jwrong
,
s
cale
=
true
,
true
,
one
(
Float64
)
fwrong
,
jwrong
,
s
iter
=
true
,
true
,
0
while
(
fwrong
||
jwrong
)
&&
scale
>.
0005
while
(
fwrong
||
jwrong
)
&&
scale
>.
0005
# Move along the direction p. Set a candidate value for x and predicted improvement for f.
# Move along the direction p. Set a candidate value for x and predicted improvement for f.
@inbounds
for
i
=
1
:
n
@inbounds
for
i
=
1
:
n
...
@@ -242,6 +243,7 @@ function trustregion(f!::Function, j!::Function, x0::Vector{Float64}, factor::Fl
...
@@ -242,6 +243,7 @@ function trustregion(f!::Function, j!::Function, x0::Vector{Float64}, factor::Fl
# If evaluation of the residuals returns an error, then keep the same
# If evaluation of the residuals returns an error, then keep the same
# direction but reduce the step length.
# direction but reduce the step length.
scale
*=
.
5
scale
*=
.
5
siter
+=
1
continue
continue
end
end
fnorm1
=
norm
(
wa
.
fval1
)
fnorm1
=
norm
(
wa
.
fval1
)
...
@@ -337,6 +339,7 @@ function trustregion(f!::Function, j!::Function, x0::Vector{Float64}, factor::Fl
...
@@ -337,6 +339,7 @@ function trustregion(f!::Function, j!::Function, x0::Vector{Float64}, factor::Fl
wa
.
fval
[
i
]
=
wa
.
fval0
[
i
]
wa
.
fval
[
i
]
=
wa
.
fval0
[
i
]
end
end
scale
*=
.
5
scale
*=
.
5
siter
+=
1
jwrong
=
true
jwrong
=
true
end
end
if
fwrong
||
jwrong
if
fwrong
||
jwrong
...
@@ -345,6 +348,22 @@ function trustregion(f!::Function, j!::Function, x0::Vector{Float64}, factor::Fl
...
@@ -345,6 +348,22 @@ function trustregion(f!::Function, j!::Function, x0::Vector{Float64}, factor::Fl
return
info
return
info
end
end
end
end
# Update the value of the scale parameter.
if
siter
>
0
# Something went wrong when evaluating the nonlinear equations or the
# jacobian matrix, and the scale parameter had to be reduced. The scale
# parameter is updated with its average across newton iterations (first
# while-loop). This avoids to use the default value of the scale
# parameter (1.0) in the following iteration and reduces the number of
# iterations. The average value of the scale parameter is recursively
# computed.
scale
=
((
iter
-
1
)
*
scale0
+
scale
)
/
iter
else
# Increase the value of the scale parameter by 5 percent if the previous
# step provided by the dogleg routine did not cause any trouble...
scale
=
min
(
scale0
*
1.05
,
1.0
)
end
scale0
=
scale
@label
mainloop
@label
mainloop
end
end
if
info
==
0
&&
iter
>
maxiter
if
info
==
0
&&
iter
>
maxiter
...
...
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