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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dynare
dynare
Commits
158b7462
Verified
Commit
158b7462
authored
1 year ago
by
Sébastien Villemot
Browse files
Options
Downloads
Patches
Plain Diff
solve_two_boundaries.m: strip down the number of input arguments
parent
b36507d0
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
matlab/perfect-foresight-models/solve_block_decomposed_problem.m
+2
-2
2 additions, 2 deletions
...perfect-foresight-models/solve_block_decomposed_problem.m
matlab/solve_two_boundaries.m
+14
-25
14 additions, 25 deletions
matlab/solve_two_boundaries.m
with
16 additions
and
27 deletions
matlab/perfect-foresight-models/solve_block_decomposed_problem.m
+
2
−
2
View file @
158b7462
...
@@ -59,7 +59,6 @@ nblocks = length(M_.block_structure.block);
...
@@ -59,7 +59,6 @@ nblocks = length(M_.block_structure.block);
per_block_status
=
struct
(
'success'
,
cell
(
1
,
nblocks
),
'error'
,
cell
(
1
,
nblocks
),
'iterations'
,
cell
(
1
,
nblocks
));
per_block_status
=
struct
(
'success'
,
cell
(
1
,
nblocks
),
'error'
,
cell
(
1
,
nblocks
),
'iterations'
,
cell
(
1
,
nblocks
));
for
blk
=
1
:
nblocks
for
blk
=
1
:
nblocks
y_index
=
M_
.
block_structure
.
block
(
blk
)
.
variable
(
end
-
M_
.
block_structure
.
block
(
blk
)
.
mfs
+
1
:
end
);
fh_dynamic
=
str2func
(
sprintf
(
'%s.sparse.block.dynamic_%d'
,
M_
.
fname
,
blk
));
fh_dynamic
=
str2func
(
sprintf
(
'%s.sparse.block.dynamic_%d'
,
M_
.
fname
,
blk
));
switch
M_
.
block_structure
.
block
(
blk
)
.
Simulation_Type
switch
M_
.
block_structure
.
block
(
blk
)
.
Simulation_Type
...
@@ -90,9 +89,10 @@ for blk = 1:nblocks
...
@@ -90,9 +89,10 @@ for blk = 1:nblocks
iter
=
[];
iter
=
[];
case
{
3
,
4
,
6
,
7
}
% solve{Forward,Backward}{Simple,Complete}
case
{
3
,
4
,
6
,
7
}
% solve{Forward,Backward}{Simple,Complete}
is_forward
=
M_
.
block_structure
.
block
(
blk
)
.
Simulation_Type
==
3
||
M_
.
block_structure
.
block
(
blk
)
.
Simulation_Type
==
6
;
is_forward
=
M_
.
block_structure
.
block
(
blk
)
.
Simulation_Type
==
3
||
M_
.
block_structure
.
block
(
blk
)
.
Simulation_Type
==
6
;
y_index
=
M_
.
block_structure
.
block
(
blk
)
.
variable
(
end
-
M_
.
block_structure
.
block
(
blk
)
.
mfs
+
1
:
end
);
[
y
,
T
,
success
,
maxblkerror
,
iter
]
=
solve_one_boundary
(
fh_dynamic
,
y
,
exo_simul
,
M_
.
params
,
steady_state
,
T
,
y_index
,
M_
.
block_structure
.
block
(
blk
)
.
NNZDerivatives
,
options_
.
periods
,
M_
.
block_structure
.
block
(
blk
)
.
is_linear
,
blk
,
M_
.
maximum_lag
,
options_
.
simul
.
maxit
,
options_
.
dynatol
.
f
,
cutoff
,
options_
.
stack_solve_algo
,
is_forward
,
true
,
false
,
M_
,
options_
);
[
y
,
T
,
success
,
maxblkerror
,
iter
]
=
solve_one_boundary
(
fh_dynamic
,
y
,
exo_simul
,
M_
.
params
,
steady_state
,
T
,
y_index
,
M_
.
block_structure
.
block
(
blk
)
.
NNZDerivatives
,
options_
.
periods
,
M_
.
block_structure
.
block
(
blk
)
.
is_linear
,
blk
,
M_
.
maximum_lag
,
options_
.
simul
.
maxit
,
options_
.
dynatol
.
f
,
cutoff
,
options_
.
stack_solve_algo
,
is_forward
,
true
,
false
,
M_
,
options_
);
case
{
5
,
8
}
% solveTwoBoundaries{Simple,Complete}
case
{
5
,
8
}
% solveTwoBoundaries{Simple,Complete}
[
y
,
T
,
success
,
maxblkerror
,
iter
]
=
solve_two_boundaries
(
fh_dynamic
,
y
,
exo_simul
,
M_
.
params
,
steady_state
,
T
,
y_index
,
M_
.
block_structure
.
block
(
blk
)
.
NNZDerivatives
,
options_
.
periods
,
M_
.
block_structure
.
block
(
blk
)
.
is_linear
,
blk
,
M_
.
maximum_lag
,
options_
.
simul
.
maxit
,
options_
.
dynatol
.
f
,
cutoff
,
options_
.
stack_solve_algo
,
options_
,
M_
);
[
y
,
T
,
success
,
maxblkerror
,
iter
]
=
solve_two_boundaries
(
fh_dynamic
,
y
,
exo_simul
,
steady_state
,
T
,
blk
,
cutoff
,
options_
,
M_
);
end
end
tmp
=
y
(
M_
.
block_structure
.
block
(
blk
)
.
variable
,
:);
tmp
=
y
(
M_
.
block_structure
.
block
(
blk
)
.
variable
,
:);
...
...
This diff is collapsed.
Click to expand it.
matlab/solve_two_boundaries.m
+
14
−
25
View file @
158b7462
function
[
y
,
T
,
success
,
max_res
,
iter
]
=
solve_two_boundaries
(
fh
,
y
,
x
,
params
,
steady_state
,
T
,
y_index
,
nze
,
periods
,
is_linear
,
Block_Num
,
y_kmin
,
maxit_
,
solve_tolf
,
cutoff
,
stack_solve_algo
,
options_
,
M_
)
function
[
y
,
T
,
success
,
max_res
,
iter
]
=
solve_two_boundaries
(
fh
,
y
,
x
,
steady_state
,
T
,
Block_Num
,
cutoff
,
options_
,
M_
)
% Computes the deterministic simulation of a block of equation containing
% Computes the deterministic simulation of a block of equation containing
% both lead and lag variables using relaxation methods
% both lead and lag variables using relaxation methods
%
%
...
@@ -6,27 +6,11 @@ function [y, T, success, max_res, iter] = solve_two_boundaries(fh, y, x, params,
...
@@ -6,27 +6,11 @@ function [y, T, success, max_res, iter] = solve_two_boundaries(fh, y, x, params,
% fh [handle] function handle to the dynamic file for the block
% fh [handle] function handle to the dynamic file for the block
% y [matrix] All the endogenous variables of the model
% y [matrix] All the endogenous variables of the model
% x [matrix] All the exogenous variables of the model
% x [matrix] All the exogenous variables of the model
% params [vector] All the parameters of the model
% steady_state [vector] steady state of the model
% steady_state [vector] steady state of the model
% T [matrix] Temporary terms
% T [matrix] Temporary terms
% y_index [vector of int] The index of the endogenous variables of
% the block
% nze [integer] number of non-zero elements in the
% jacobian matrix
% periods [integer] number of simulation periods
% is_linear [logical] Whether the block is linear
% Block_Num [integer] block number
% Block_Num [integer] block number
% y_kmin [integer] maximum number of lag in the model
% maxit_ [integer] maximum number of iteration in Newton
% solve_tolf [double] convergence criteria
% cutoff [double] cutoff to correct the direction in Newton in case
% cutoff [double] cutoff to correct the direction in Newton in case
% of singular jacobian matrix
% of singular jacobian matrix
% stack_solve_algo [integer] linear solver method used in the
% Newton algorithm :
% - 1 sprse LU
% - 2 GMRES
% - 3 BicGStab
% - 4 Optimal path length
% options_ [structure] storing the options
% options_ [structure] storing the options
% M_ [structure] Model description
% M_ [structure] Model description
%
%
...
@@ -57,11 +41,16 @@ function [y, T, success, max_res, iter] = solve_two_boundaries(fh, y, x, params,
...
@@ -57,11 +41,16 @@ function [y, T, success, max_res, iter] = solve_two_boundaries(fh, y, x, params,
% You should have received a copy of the GNU General Public License
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
Blck_size
=
M_
.
block_structure
.
block
(
Block_Num
)
.
mfs
;
y_index
=
M_
.
block_structure
.
block
(
Block_Num
)
.
variable
(
end
-
Blck_size
+
1
:
end
);
periods
=
options_
.
periods
;
y_kmin
=
M_
.
maximum_lag
;
stack_solve_algo
=
options_
.
stack_solve_algo
;
verbose
=
options_
.
verbosity
;
verbose
=
options_
.
verbosity
;
cvg
=
false
;
cvg
=
false
;
iter
=
0
;
iter
=
0
;
Blck_size
=
size
(
y_index
,
2
);
correcting_factor
=
0.01
;
correcting_factor
=
0.01
;
ilu_setup
.
droptol
=
1e-10
;
ilu_setup
.
droptol
=
1e-10
;
ilu_setup
.
type
=
'ilutp'
;
ilu_setup
.
type
=
'ilutp'
;
...
@@ -72,11 +61,11 @@ ilu_setup.udiag = 0;
...
@@ -72,11 +61,11 @@ ilu_setup.udiag = 0;
max_resa
=
1e100
;
max_resa
=
1e100
;
lambda
=
1
;
% Length of Newton step (unused for stack_solve_algo=4)
lambda
=
1
;
% Length of Newton step (unused for stack_solve_algo=4)
reduced
=
0
;
reduced
=
0
;
while
~
(
cvg
||
iter
>
maxit
_
)
while
~
(
cvg
||
iter
>
options_
.
simul
.
maxit
)
r
=
NaN
(
Blck_size
,
periods
);
r
=
NaN
(
Blck_size
,
periods
);
g1a
=
spalloc
(
Blck_size
*
periods
,
Blck_size
*
periods
,
nze
*
periods
);
g1a
=
spalloc
(
Blck_size
*
periods
,
Blck_size
*
periods
,
M_
.
block_structure
.
block
(
Block_Num
)
.
NNZDerivatives
*
periods
);
for
it_
=
y_kmin
+
(
1
:
periods
)
for
it_
=
y_kmin
+
(
1
:
periods
)
[
yy
,
T
(:,
it_
),
r
(:,
it_
-
y_kmin
),
g1
]
=
fh
(
dynendo
(
y
,
it_
,
M_
),
x
(
it_
,
:),
params
,
steady_state
,
...
[
yy
,
T
(:,
it_
),
r
(:,
it_
-
y_kmin
),
g1
]
=
fh
(
dynendo
(
y
,
it_
,
M_
),
x
(
it_
,
:),
M_
.
params
,
steady_state
,
...
M_
.
block_structure
.
block
(
Block_Num
)
.
g1_sparse_rowval
,
...
M_
.
block_structure
.
block
(
Block_Num
)
.
g1_sparse_rowval
,
...
M_
.
block_structure
.
block
(
Block_Num
)
.
g1_sparse_colval
,
...
M_
.
block_structure
.
block
(
Block_Num
)
.
g1_sparse_colval
,
...
M_
.
block_structure
.
block
(
Block_Num
)
.
g1_sparse_colptr
,
T
(:,
it_
));
M_
.
block_structure
.
block
(
Block_Num
)
.
g1_sparse_colptr
,
T
(:,
it_
));
...
@@ -101,10 +90,10 @@ while ~(cvg || iter>maxit_)
...
@@ -101,10 +90,10 @@ while ~(cvg || iter>maxit_)
end
end
if
~
isreal
(
max_res
)
||
isnan
(
max_res
)
if
~
isreal
(
max_res
)
||
isnan
(
max_res
)
cvg
=
false
;
cvg
=
false
;
elseif
is_linear
&&
iter
>
0
elseif
M_
.
block_structure
.
block
(
Block_Num
)
.
is_linear
&&
iter
>
0
cvg
=
true
;
cvg
=
true
;
else
else
cvg
=
(
max_res
<
solve_
tolf
);
cvg
=
(
max_res
<
options_
.
dyna
tol
.
f
);
end
end
if
~
cvg
if
~
cvg
if
iter
>
0
if
iter
>
0
...
@@ -308,7 +297,7 @@ while ~(cvg || iter>maxit_)
...
@@ -308,7 +297,7 @@ while ~(cvg || iter>maxit_)
g
=
(
ra
'*g1a)'
;
g
=
(
ra
'*g1a)'
;
f
=
0.5
*
ra
'*
ra
;
f
=
0.5
*
ra
'*
ra
;
p
=
-
g1a
\
ra
;
p
=
-
g1a
\
ra
;
[
yn
,
f
,
ra
,
check
]
=
lnsrch1
(
ya
,
f
,
g
,
p
,
stpmax
,
@
lnsrch1_wrapper_two_boundaries
,
nn
,
nn
,
options_
.
solve_tolx
,
fh
,
Block_Num
,
y
,
y_index
,
x
,
params
,
steady_state
,
T
,
periods
,
Blck_size
,
M_
);
[
yn
,
f
,
ra
,
check
]
=
lnsrch1
(
ya
,
f
,
g
,
p
,
stpmax
,
@
lnsrch1_wrapper_two_boundaries
,
nn
,
nn
,
options_
.
solve_tolx
,
fh
,
Block_Num
,
y
,
y_index
,
x
,
M_
.
params
,
steady_state
,
T
,
periods
,
Blck_size
,
M_
);
dx
=
ya
-
yn
;
dx
=
ya
-
yn
;
y
(
y_index
,
y_kmin
+
(
1
:
periods
))
=
reshape
(
yn
'
,
length
(
y_index
),
periods
);
y
(
y_index
,
y_kmin
+
(
1
:
periods
))
=
reshape
(
yn
'
,
length
(
y_index
),
periods
);
end
end
...
@@ -319,7 +308,7 @@ while ~(cvg || iter>maxit_)
...
@@ -319,7 +308,7 @@ while ~(cvg || iter>maxit_)
end
end
end
end
if
(
iter
>
maxit
_
)
if
iter
>
options_
.
simul
.
maxit
if
verbose
if
verbose
printline
(
41
)
printline
(
41
)
%disp(['No convergence after ' num2str(iter,'%4d') ' iterations in Block ' num2str(Block_Num,'%d')])
%disp(['No convergence after ' num2str(iter,'%4d') ' iterations in Block ' num2str(Block_Num,'%d')])
...
...
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