Commit f4dc2ee7 by Willi Mutschler

🐛 Fix wrong third-order computation in pruned state space system

Related to #1706

✅ Add unit test for pruned state space up to order 3

//

Changed tolerance in new test 
parent f69cd149
 % % bivmom.m Date: 1/11/2004 % This Matlab program computes the product moment of X_1^{p_1}X_2^{p_2}, % where X_1 and X_2 are standard bivariate normally distributed. function [y,dy] = bivmom(p,rho) % Computes the product moment (and its derivative with respect to standard % errors and correlation parameters) of X_1^{p_1}X_2^{p_2}, where X_1 and X_2 % are standard bivariate normally distributed. % n : dimension of X % rho: correlation coefficient between X_1 and X_2 % Reference: Kotz, Balakrishnan, and Johnson (2000), Continuous Multivariate % Distributions, Vol. 1, p.261 % Note that there is a typo in Eq.(46.25), there should be an extra rho in front % of the equation. % Usage: bivmom(p,rho) % % Retrieved from http://www-2.rotman.utoronto.ca/~kan/papers/prodmom.zip % This function is part of replication codes of the following paper: % ========================================================================= % INPUTS % p [2 by 1] powers of X_{1} and X_{2} % rho [1 by 1] correlation coefficient between X_1 and X_2 % ------------------------------------------------------------------------- % OUTPUTS % y [1 by 1] product moment E[X_1^{p_1}X_2^{p_2}] % dy [1 by 1] derivative of y wrt to rho % ------------------------------------------------------------------------- % This function is based upon bivmom.m which is part of replication codes % of the following paper: % Kan, R.: "From moments of sum to moments of product." Journal of % Multivariate Analysis, 2008, vol. 99, issue 3, pages 542-554. % bivmom.m can be retrieved from http://www-2.rotman.utoronto.ca/~kan/papers/prodmom.zip % Further references: % Kotz, Balakrishnan, and Johnson (2000), Continuous Multivariate Distributions, Vol. 1, p.261 % Note that there is a typo in Eq.(46.25), there should be an extra rho in front % of the equation. % ========================================================================= % Copyright (C) 2008-2015 Raymond Kan % Copyright (C) 2019-2020 Dynare Team ... ... @@ -33,7 +41,6 @@ % You should have received a copy of the GNU General Public License % along with Dynare. If not, see . % ========================================================================= function [y,dy] = bivmom(p,rho) s1 = p(1); s2 = p(2); rho2 = rho^2; ... ...
 ... ... @@ -15,12 +15,13 @@ function k = commutation(n, m, sparseflag) % This function is called by % * get_perturbation_params_derivs.m (previously getH.m) % * get_identification_jacobians.m (previously getJJ.m) % * pruned_state_space_system.m % ------------------------------------------------------------------------- % This function calls % * vec (embedded) % ========================================================================= % Copyright (C) 1997 Tom Minka % Copyright (C) 2019 Dynare Team % Copyright (C) 2019-2020 Dynare Team % % This file is part of Dynare. % ... ... @@ -47,24 +48,12 @@ if nargin < 3 sparseflag = 0; end if 0 % first method i = 1:(n*m); a = reshape(i, n, m); j = vec(transpose(a)); k = zeros(n*m,n*m); for r = i k(r, j(r)) = 1; end if sparseflag k = reshape(kron(vec(speye(n)), speye(m)), n*m, n*m); else % second method k = reshape(kron(vec(eye(n)), eye(m)), n*m, n*m); end if sparseflag ~= 0 k = sparse(k); end function V = vec(A) V = A(:); end ... ...