From 21693416399dd97e7b155f6293606166ea6bcd41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Mon, 15 Apr 2019 15:24:10 +0200 Subject: [PATCH] Move source code of gensylv and dynare_simul_ MEX to the same place as other MEX --- dynare++/extern/matlab/dynare_simul.m | 174 ------------------ dynare++/sylv/Makefile.am | 2 +- dynare++/sylv/matlab/gensylv.m | 76 -------- license.txt | 6 + mex/build/dynare_simul_.am | 4 +- mex/build/gensylv.am | 2 +- mex/sources/Makefile.am | 4 +- .../sources/dynare_simul_/dynare_simul_.cc | 20 +- .../matlab => mex/sources/gensylv}/gensylv.cc | 20 +- 9 files changed, 51 insertions(+), 257 deletions(-) delete mode 100644 dynare++/extern/matlab/dynare_simul.m delete mode 100644 dynare++/sylv/matlab/gensylv.m rename dynare++/extern/matlab/dynare_simul.cc => mex/sources/dynare_simul_/dynare_simul_.cc (86%) rename {dynare++/sylv/matlab => mex/sources/gensylv}/gensylv.cc (79%) diff --git a/dynare++/extern/matlab/dynare_simul.m b/dynare++/extern/matlab/dynare_simul.m deleted file mode 100644 index 32ac8dc57..000000000 --- a/dynare++/extern/matlab/dynare_simul.m +++ /dev/null @@ -1,174 +0,0 @@ -% -% SYNOPSIS -% -% r = dynare_simul(name, shocks) -% r = dynare_simul(name, prefix, shocks) -% r = dynare_simul(name, shocks, start) -% r = dynare_simul(name, prefix, shocks, start) -% -% name name of MAT-file produced by dynare++ -% prefix prefix of variables in the MAT-file -% shocks matrix of shocks -% start zero period value -% -% Note that this file requires the dynare_simul_ DLL to be in the path. -% This DLL is distributed with Dynare, under the mex/matlab or mex/octave -% subdirectory. -% -% SEMANTICS -% -% The command reads a decision rule from the MAT-file having the given -% prefix. Then it starts simulating the decision rule with zero time value -% equal to the given start. It uses the given shocks for the simulation. If -% the start is not given, the state about which the decision rule is -% centralized is taken (called fix point, or stochastic steady state, take -% your pick). -% -% prefix Use the prefix with which you called dynare++, the default -% prefix in dynare++ is 'dyn'. -% shocks Number of rows must be a number of exogenous shocks, -% number of columns gives the number of simulated -% periods. NaNs and Infs in the matrix are substitued by -% draws from the normal distribution using the covariance -% matrix given in the model file. -% start Vector of endogenous variables in the ordering given by -% _vars. -% -% Seed for random generator is derived from calling rand(1,1). Therefore, -% seeding can be controlled with rand('state') and rand('state',some_seed). -% -% EXAMPLES -% -% All examples suppose that the prefix is 'dyn' and that your_model.mat -% has been loaded into Matlab. -% -% 1. response to permanent negative shock to the third exo var EPS3 for -% 100 periods -% -% shocks = zeros(4,100); % 4 exogenous variables in the model -% shocks(dyn_i_EPS3,:) = -0.1; % the permanent shock to EPS3 -% r = dynare_simul('your_model.mat',shocks); -% -% 2. one stochastic simulation for 100 periods -% -% shocks = zeros(4,100)./0; % put NaNs everywhere -% r = dynare_simul('your_model.mat',shocks); -% -% 3. one stochastic simulation starting at 75% undercapitalized economy -% -% shocks = zeros(4,100)./0; % put NaNs everywhere -% ystart = dyn_ss; % get copy of DR fix point -% ystart(dyn_i_K) = 0.75*dyn_ss(dyn_i_K); % scale down the capital -% r = dynare_simul('your_model.mat',shocks,ystart); -% -% -% SEE ALSO -% -% "DSGE Models with Dynare++. A Tutorial.", Ondra Kamenik, 2005 - -% Copyright (C) 2005-2011, Ondra Kamenik - -function r = dynare_simul(varargin) - -if exist('dynare_simul_') ~= 3 - error('Can''t find dynare_simul_ DLL in the path. The simplest way to add it is to run Dynare once in this session.') -end - -% get the file name and load data -fname = varargin{1}; -eval(['load ' fname]); - -% set prefix, shocks, ystart -if ischar(varargin{2}) - prefix = varargin{2}; - if length(varargin) == 3 - shocks = varargin{3}; - ystart = NaN; - elseif length(varargin) == 4 - shocks = varargin{3}; - ystart = varargin{4}; - else - error('Wrong number of parameters.'); - end -else - prefix = 'dyn'; - if length(varargin) == 2 - shocks = varargin{2}; - ystart = NaN; - elseif length(varargin) == 3 - shocks = varargin{2}; - ystart = varargin{3}; - else - error('Wrong number of parameters.'); - end -end - -% load all needed variables but prefix_g_* -if (exist([prefix '_nstat'])) - nstat = eval([prefix '_nstat']); -else - error(['Could not find variable ' prefix '_nstat in workspace']); -end -if (exist([prefix '_npred'])) - npred = eval([prefix '_npred']); -else - error(['Could not find variable ' prefix '_npred in workspace']); -end -if (exist([prefix '_nboth'])) - nboth = eval([prefix '_nboth']); -else - error(['Could not find variable ' prefix '_nboth in workspace']); -end -if (exist([prefix '_nforw'])) - nforw = eval([prefix '_nforw']); -else - error(['Could not find variable ' prefix '_nforw in workspace']); -end -if (exist([prefix '_ss'])) - ss = eval([prefix '_ss']); -else - error(['Could not find variable ' prefix '_ss in workspace']); -end -if (exist([prefix '_vcov_exo'])) - vcov_exo = eval([prefix '_vcov_exo']); -else - error(['Could not find variable ' prefix '_vcov_exo in workspace']); -end -nexog = size(vcov_exo,1); - -if isnan(ystart) - ystart = ss; -end - -% newer version of dynare++ doesn't return prefix_g_0, we make it here if -% it does not exist in workspace -g_zero = [prefix '_g_0']; -if (~ exist(g_zero)) - eval([ g_zero '= zeros(nstat+npred+nboth+nforw,1);']); -end - -% make derstr a string of comma seperated existing prefix_g_* -derstr = [',' g_zero]; -order = 1; -cont = 1; -while cont == 1 - g_ord = [prefix '_g_' num2str(order)]; - if (exist(g_ord)) - derstr = [derstr ',' g_ord]; - order = order + 1; - else - cont = 0; - end -end - -% set seed -seed = ceil(10000*rand(1,1)); - -% call dynare_simul_ -command = ['[err,r]=dynare_simul_(' num2str(order-1) ',nstat,npred,nboth,nforw,' ... - 'nexog,ystart,shocks,vcov_exo,seed,ss' derstr ');']; -eval(command); - -if err - error('Simulation failed') -end diff --git a/dynare++/sylv/Makefile.am b/dynare++/sylv/Makefile.am index a5dd5bc4e..bc7a9544c 100644 --- a/dynare++/sylv/Makefile.am +++ b/dynare++/sylv/Makefile.am @@ -1,6 +1,6 @@ SUBDIRS = cc testing -EXTRA_DIST = sylvester.tex change_log.html matlab +EXTRA_DIST = sylvester.tex change_log.html if HAVE_PDFLATEX pdf-local: sylvester.pdf diff --git a/dynare++/sylv/matlab/gensylv.m b/dynare++/sylv/matlab/gensylv.m deleted file mode 100644 index 56f5f0e73..000000000 --- a/dynare++/sylv/matlab/gensylv.m +++ /dev/null @@ -1,76 +0,0 @@ -% -% GENSYLV solves the following matrix equation: -% A*X + [0 B]*X*kron(C,..,C) = D, -% where -% A ...... regular (n,n) matrix, -% [0 B] .. (n,n) matrix with a few first -% columns equal to zeros -% B ...... rectangular (n, nz) matrix with nz<=n -% C ...... regular (m,m) matrix, whose spectrum is -% within (-1, 1) -% kron(C,..,C) -% ...... Kronecker power of C of order 'order' -% D ..... rectangular (n, m^order) matrix. -% -% [err, X] = gensylv(order, A, B, C, D) -% returns err a scalar where 1 indicates failure, 0 indicates success -% and X as the solution, doesn't perform any checks -% -% [err, X, par] = gensylv(order, A, B, C, D) -% solves the system, and performs checks. 'par' is struct -% containing information about solution and error norms -% returned by the check. This is a list of the struct -% members, some of them may be missing in actual returned -% value: -% method = method used for solution recursive/iterative -% convergence_tol = convergence tolerance for iter. method -% max_num_iter = max number of steps for iter. method -% bs_norm = Bavely Stewart log10 norm for diagonalization -% converged = convergence status for iterative method -% iter_last_norm = residual norm of the last step of iterations -% num_iter = number of iterations performed -% f_err1 = norm 1 of abs. error C-V*F*inv(V) -% f_errI = norm Inf of abs. error C-V*F*inv(V) -% viv_err1 = norm 1 of abs. error I-V*inv(V) -% viv_errI = norm Inf of abs. error I-V*inv(V) -% ivv_err1 = norm 1 of abs. error I-inv(V)*V -% ivv_errI = norm Inf of abs. error I-inv(V)*V -% f_blocks = number of diagonal blocks of F -% f_largest = size of largest diagonal block in F -% f_zeros = number of off diagonal zeros in F -% f_offdiag = number of all offdiagonal elements in F -% rcondA1 = reciprocal cond 1 number of A -% rcondAI = reciprocal cond Inf number of A -% eig_min = minimum eigenvalue of vectorized system -% mat_err1 = rel. matrix 1 norm of A*X-[0 B]*X*kron(C,..,C)-D -% mat_errI = rel. matrix Inf norm of --"-- -% mat_errF = rel. matrix Frobenius norm of --"-- -% vec_err1 = rel. vector 1 norm of --"-- -% vec_errI = rel. vector Inf norm of --"-- -% cpu_time = CPU time needed for solution in CPU seconds -% - -% $Header: /var/lib/cvs/dynare_cpp/sylv/matlab/gensylv.m,v 1.1.1.1 2004/06/04 13:01:13 kamenik Exp $ -% Tag $Name: $ - -function [err, X, varargout] = gensylv(order, A, B, C, D) - -% in Windows, ensure that aa_gensylv.dll is loaded, this prevents -% clearing the function and a successive Matlab crash -if strcmp('PCWIN', computer) - if ~ libisloaded('aa_gensylv') - loadlibrary('aa_gensylv', 'dummy'); - end -end - -% launch aa_gensylv -if nargout == 2 - X = aa_gensylv(order, A, B, C, D); -elseif nargout == 3 - [X, par] = aa_gensylv(order, A, B, C, D); - varargout(1) = {par}; -else - error('Must have 2 or 3 output arguments.'); -end -err = 0; - \ No newline at end of file diff --git a/license.txt b/license.txt index 875fa449f..11c8b7a78 100644 --- a/license.txt +++ b/license.txt @@ -268,6 +268,12 @@ Copyright: 2010 Yannick Kalantzis 2019 Dynare Team License: GPL-3+ +Files: mex/sources/dynare_simul_/dynare_simul_.cc + mex/sources/gensylv/gensylv.cc +Copyright: 2005-2011 Ondra Kamenik + 2019 Dynare Team +License: GPL-3+ + Files: mex/sources/sobol/sobol.hh mex/sources/sobol/initialize_v_array.hh mex/sources/sobol/initialize_v_array.inc Copyright: 2009 John Burkardt diff --git a/mex/build/dynare_simul_.am b/mex/build/dynare_simul_.am index 83173a180..550bd7436 100644 --- a/mex/build/dynare_simul_.am +++ b/mex/build/dynare_simul_.am @@ -7,10 +7,10 @@ dynare_simul__CXXFLAGS = $(AM_CXXFLAGS) $(THREAD_CXXFLAGS) dynare_simul__LDFLAGS = $(AM_LDFLAGS) $(LDFLAGS_MATIO) dynare_simul__LDADD = ../libdynare++/libdynare++.a $(LIBADD_MATIO) -nodist_dynare_simul__SOURCES = dynare_simul.cc +nodist_dynare_simul__SOURCES = dynare_simul_.cc BUILT_SOURCES = $(nodist_dynare_simul__SOURCES) CLEANFILES = $(nodist_dynare_simul__SOURCES) -%.cc: $(top_srcdir)/../../../dynare++/extern/matlab/%.cc +%.cc: $(top_srcdir)/../../sources/dynare_simul_/%.cc $(LN_S) -f $< $@ diff --git a/mex/build/gensylv.am b/mex/build/gensylv.am index 34f2cd682..b664759aa 100644 --- a/mex/build/gensylv.am +++ b/mex/build/gensylv.am @@ -9,5 +9,5 @@ nodist_gensylv_SOURCES = gensylv.cc BUILT_SOURCES = $(nodist_gensylv_SOURCES) CLEANFILES = $(nodist_gensylv_SOURCES) -%.cc: $(top_srcdir)/../../../dynare++/sylv/matlab/%.cc +%.cc: $(top_srcdir)/../../sources/gensylv/%.cc $(LN_S) -f $< $@ diff --git a/mex/sources/Makefile.am b/mex/sources/Makefile.am index 4d7007ee1..654100d3a 100644 --- a/mex/sources/Makefile.am +++ b/mex/sources/Makefile.am @@ -11,7 +11,9 @@ EXTRA_DIST = \ ms-sbvar \ block_kalman_filter \ sobol \ - local_state_space_iterations + local_state_space_iterations \ + gensylv \ + dynare_simul_ clean-local: rm -rf `find mex/sources -name *.o` diff --git a/dynare++/extern/matlab/dynare_simul.cc b/mex/sources/dynare_simul_/dynare_simul_.cc similarity index 86% rename from dynare++/extern/matlab/dynare_simul.cc rename to mex/sources/dynare_simul_/dynare_simul_.cc index 2d84a5111..373c676f1 100644 --- a/dynare++/extern/matlab/dynare_simul.cc +++ b/mex/sources/dynare_simul_/dynare_simul_.cc @@ -1,4 +1,22 @@ -// Copyright (C) 2005-2011, Ondra Kamenik +/* + * Copyright (C) 2005-2011 Ondra Kamenik + * Copyright (C) 2019 Dynare Team + * + * This file is part of Dynare. + * + * Dynare is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Dynare is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Dynare. If not, see . + */ // This is the mexFunction providing interface to // DecisionRule<>::simulate(). It takes the following input diff --git a/dynare++/sylv/matlab/gensylv.cc b/mex/sources/gensylv/gensylv.cc similarity index 79% rename from dynare++/sylv/matlab/gensylv.cc rename to mex/sources/gensylv/gensylv.cc index 5b58b8826..e520a6f5c 100644 --- a/dynare++/sylv/matlab/gensylv.cc +++ b/mex/sources/gensylv/gensylv.cc @@ -1,4 +1,22 @@ -// Copyright (C) 2005-2011, Ondra Kamenik +/* + * Copyright (C) 2005-2011 Ondra Kamenik + * Copyright (C) 2019 Dynare Team + * + * This file is part of Dynare. + * + * Dynare is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Dynare is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Dynare. If not, see . + */ #include "dynmex.h" #include "mex.h"