From c59133562c01272cb71b10b680b695a28f156a8c Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 16 Feb 2011 18:31:48 +0100 Subject: [PATCH] more short-circuit logicals in the place of element-wise logicals --- .../missing_observations_kalman_filter.m | 4 ++-- .../univariate_diffuse_kalman_filter_corr.m | 4 ++-- matlab/kalman/smoother/kalman_smoother.m | 4 ++-- matlab/ms-sbvar/cstz/csminit.m | 18 +++++++++--------- matlab/ms-sbvar/cstz/csminwel.m | 18 +++++++++--------- matlab/ms-sbvar/cstz/fn_dataext.m | 2 +- matlab/ms-sbvar/cstz/fn_datana.m | 2 +- matlab/ms-sbvar/cstz/fn_fcstidcnd.m | 6 +++--- matlab/ms-sbvar/msstart2.m | 12 ++++++------ matlab/parallel/masterParallel.m | 2 +- 10 files changed, 36 insertions(+), 36 deletions(-) diff --git a/matlab/kalman/likelihood/missing_observations_kalman_filter.m b/matlab/kalman/likelihood/missing_observations_kalman_filter.m index fe6d43c53..af84bceef 100644 --- a/matlab/kalman/likelihood/missing_observations_kalman_filter.m +++ b/matlab/kalman/likelihood/missing_observations_kalman_filter.m @@ -29,7 +29,7 @@ function [LIK, lik] = missing_observations_kalman_filter(T,R,Q,H,P,Y,start,mf,k % NOTES % The vector "lik" is used to evaluate the jacobian of the likelihood. -% Copyright (C) 2004-2010 Dynare Team +% Copyright (C) 2004-2011 Dynare Team % % This file is part of Dynare. % @@ -59,7 +59,7 @@ oldK = Inf; notsteady = 1; % Steady state flag. F_singular = 1; -while notsteady & tkalman_tol)==0 & rank(Pinf,crit)==0); + if newRank && (any(diag(Za*Pinf*Za')>kalman_tol)==0 && rank(Pinf,crit)==0); options_.diffuse_d = icc; newRank=0; disp('WARNING: Change in OPTIONS_.DIFFUSE_D in univariate DKF') diff --git a/matlab/kalman/smoother/kalman_smoother.m b/matlab/kalman/smoother/kalman_smoother.m index bc7ae38b2..1e9bbb2e0 100644 --- a/matlab/kalman/smoother/kalman_smoother.m +++ b/matlab/kalman/smoother/kalman_smoother.m @@ -27,7 +27,7 @@ function [alphahat,epsilonhat,etahat,atilde,P,aK,PK,decomp] = kalman_smoother(T, % Models", S.J. Koopman and J. Durbin (2003, in Journal of Time Series % Analysis, vol. 24(1), pp. 85-98). -% Copyright (C) 2004-2010 Dynare Team +% Copyright (C) 2004-2011 Dynare Team % % This file is part of Dynare. % @@ -87,7 +87,7 @@ P(:,:,1) = P0; t = 0; notsteady = 1; F_singular = 1; -while notsteady & t 0) & (f0-f > -(1-THETA)*dfhat*lambda) ); - if shrinkSignal & ( (lambda>lambdaPeak) | (lambda<0) ) - if (lambda>0) & ((~shrink) | (lambda/factor <= lambdaPeak)) + if shrinkSignal && ( (lambda>lambdaPeak) || (lambda<0) ) + if (lambda>0) && ((~shrink) || (lambda/factor <= lambdaPeak)) shrink=1; factor=factor^.6; while lambda/factor <= lambdaPeak factor=factor^.6; end - %if (abs(lambda)*(factor-1)*dxnorm < MINDX) | (abs(lambda)*(factor-1) < MINLAMB) + %if (abs(lambda)*(factor-1)*dxnorm < MINDX) || (abs(lambda)*(factor-1) < MINLAMB) if abs(factor-1)lambdaPeak) + if (lambdalambdaPeak) lambdaMax=lambda; end lambda=lambda/factor; if abs(lambda) < MINLAMB - if (lambda > 0) & (f0 <= fhat) + if (lambda > 0) && (f0 <= fhat) % try going against gradient, which may be inaccurate if dispIndx, lambda = -lambda*factor^6, end else @@ -160,11 +160,11 @@ else done = 1; end end - elseif (growSignal & lambda>0) | (shrinkSignal & ((lambda <= lambdaPeak) & (lambda>0))) + elseif (growSignal && lambda>0) || (shrinkSignal && ((lambda <= lambdaPeak) && (lambda>0))) if shrink shrink=0; factor = factor^.6; - %if ( abs(lambda)*(factor-1)*dxnorm< MINDX ) | ( abs(lambda)*(factor-1)< MINLAMB) + %if ( abs(lambda)*(factor-1)*dxnorm< MINDX ) || ( abs(lambda)*(factor-1)< MINLAMB) if abs(factor-1)0) + if ( f0) fPeak=f; lambdaPeak=lambda; if lambdaMax<=lambdaPeak diff --git a/matlab/ms-sbvar/cstz/csminwel.m b/matlab/ms-sbvar/cstz/csminwel.m index f32c03533..e0d6f5ee7 100644 --- a/matlab/ms-sbvar/cstz/csminwel.m +++ b/matlab/ms-sbvar/cstz/csminwel.m @@ -85,7 +85,7 @@ while ~done % itct=itct+1; fcount = fcount+fc; % erased on 8/4/94 - % if (retcode == 1) | (abs(f1-f) < crit) + % if (retcode == 1) || (abs(f1-f) < crit) % done=1; % end % if itct > nit @@ -93,7 +93,7 @@ while ~done % retcode = -retcode; % end if retcode1 ~= 1 - if retcode1==2 | retcode1==4 + if retcode1==2 || retcode1==4 wall1=1; badg1=1; else if NumGrad @@ -113,7 +113,7 @@ while ~done %ARGLIST %save g1 g1 x1 f1 P1 P2 P3 P4 P5 P6 P7 P8 P9 P10 P11 P12 P13; end - if wall1 % & (~done) by Jinill + if wall1 % && (~done) by Jinill % Bad gradient or back and forth on step length. Possibly at % cliff edge. Try perturbing search direction. % @@ -133,7 +133,7 @@ while ~done % P5,P6,P7,P8,P9,P10,P11,P12,P13); fcount = fcount+fc; % put by Jinill if f2 < f - if retcode2==2 | retcode2==4 + if retcode2==2 || retcode2==4 wall2=1; badg2=1; else if NumGrad @@ -166,7 +166,7 @@ while ~done % P4,P5,P6,P7,P8,... % P9,P10,P11,P12,P13); fcount = fcount+fc; % put by Jinill - if retcode3==2 | retcode3==4 + if retcode3==2 || retcode3==4 wall3=1; badg3=1; else if NumGrad @@ -202,13 +202,13 @@ while ~done f1=f; f2=f; f3=f; retcode2=retcode1; retcode3=retcode1; end %how to pick gh and xh - if f3 # of forecast or impulse steps!!') @@ -142,7 +142,7 @@ end % No uncertainty at all or only random (A0,A+) % In other words, no future shocks %--------------------------------------- -if (~Sband) %| (nconstr & (length(eq_ms)==1)) +if (~Sband) %|| (nconstr && (length(eq_ms)==1)) % length(eq_ms)==1 implies one-one mapping between MS shocks and, say, FFR % if nstepsm==nconstr. If this condition does not hold, this procedure % is incorrect. I don't have time to fix it now (3/20/99). So I use @@ -175,7 +175,7 @@ else %-------------- % Condition on variables and A random %-------------- - if nconstr & Aband + if nconstr && Aband warning(' ') disp('This situation (both E and A random) is still under construction') disp('It is closely related to Waggoner and Zha ReStat Gibbs sampling method') diff --git a/matlab/ms-sbvar/msstart2.m b/matlab/ms-sbvar/msstart2.m index b72be117e..fcc4c888a 100644 --- a/matlab/ms-sbvar/msstart2.m +++ b/matlab/ms-sbvar/msstart2.m @@ -164,7 +164,7 @@ else return end % -if nEnd>0 | nStart<0 +if nEnd>0 || nStart<0 disp('Warning: this particular sample consider is out of bounds of the data!!!') return end @@ -639,7 +639,7 @@ if options_.ms.indxestima end if cnum - if options_.ms.real_pseudo_forecast & options_.ms.banact + if options_.ms.real_pseudo_forecast && options_.ms.banact for i=1:length(banstp{1}) banval{1}(1:length(banstp{1}),1) = ... yactCalyg(yAg-yFg+1:yAg-yFg+length(banstp{1}),banvar(1)) - 2; @@ -662,7 +662,7 @@ if options_.ms.indxestima %===== Converted to mg, qg, and calendar yg [yacyrghate,yacyrhate,yacqmyghate] = fn_datana(yachate,options_.ms.freq,options_.ms.log_var(1:nlogeno),options_.ms.percent_var(1:npereno)); % actual and conditional forecast growth rates - if options_.ms.indxgdls & nconstr + if options_.ms.indxgdls && nconstr keyindx = [1:nvar]; % conlab=['conditional on' ylab{PorR(1)}]; conlab=['v-conditions']; @@ -732,7 +732,7 @@ end % SpHR=A0in'*A0in; %end %% -%if ~isnan(SpHR) & ~options_.ms.contemp_reduced_form +%if ~isnan(SpHR) && ~options_.ms.contemp_reduced_form % warning(' ') % disp('Make sure you run the program with options_.ms.contemp_reduced_form =1 first.') % disp('Otherwise, the following test results such as Schwartz are incorrect.') @@ -779,8 +779,8 @@ end %***** Simply regression %X=[phi(:,3) y(:,2)-phi(:,2) y(:,1)-phi(:,7) ones(fss,1)]; -%» Y=y(:,3); -%» b=regress(Y,X) +%� Y=y(:,3); +%� b=regress(Y,X) %=== Computes the roots for the whole system. rootsinv = fn_varoots(Bhat,nvar,options_.ms.nlags ) diff --git a/matlab/parallel/masterParallel.m b/matlab/parallel/masterParallel.m index 77b94f4f7..91e485b77 100644 --- a/matlab/parallel/masterParallel.m +++ b/matlab/parallel/masterParallel.m @@ -322,7 +322,7 @@ for j=1:totCPU, case 1 - if Parallel(indPC).Local == 1 & newInstance, % 1.1 Run on the local machine. + if Parallel(indPC).Local == 1 && newInstance, % 1.1 Run on the local machine. if ~ispc, %isunix || (~matlab_ver_less_than('7.4') && ismac), if exist('OCTAVE_VERSION') command1=['octave --eval "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')" &'];