ssm estimation not working inside for loop

4 visualizaciones (últimos 30 días)
Vineet Upreti
Vineet Upreti el 15 de Dic. de 2019
Hi, I am trying to estimate an ssm model inside a loop. The model works fine ouside the loop, but fails to run inside the loop. The 'for loop' selects data correponding an identifier and then uses the estimate command to run SSM model defined outside the loop.
%Defining the SSM model
Mdl = ssm(@(params)DNSMAPPARSN(params,Yins,maturity));
options = optimoptions('fminunc','MaxFunEvals',25000,'algorithm','quasi-newton', ...
'TolFun' ,1e-8,'TolX',1e-8,'MaxIter',1000,'Display','off');
% Defining the VAR model
AR = {diag(nan(3,1))};
varmdl = varm('AR',AR);
for j = 1:29
betains = beta(nid==j,2:end); % select input data for VAR
residins = resid(nid==j,2:end);
Yins = Y(nid==j,2:end); % select input data for SSM
EstMdlVAR = estimate(varmdl, betains);
% Initial conditions based on VAR results
A0 = EstMdlVAR.AR{1};
A0 = diag(A0);
Q0 = EstMdlVAR.Covariance;
B0 = [sqrt(Q0(1,1)); 0; 0; sqrt(Q0(2,2)); 0; sqrt(Q0(3,3))];
H0 = cov(residins);
D0 = sqrt(diag(H0));
d0 = mean(D0);
mu0 = mean(betains)';
param0 = [A0; B0; d0; mu0; lambda0];
[EstMdlSSM,params] = estimate(Mdl,Yins,param0,'Display','off','options',options,...
'Univariate',true);
mu = params(end-3:end-1)'; % Get the estimated factor means
intercept = EstMdlSSM.C * mu';
deflatedYields = bsxfun(@minus,Yins,intercept');
deflatedStates = filter(EstMdlSSM,deflatedYields);
estimatedStates = bsxfun(@plus,deflatedStates,mu);
betassm(nid==j,:) = estimatedStates;
Yf(nid==j,:) = estimatedStates*EstMdlSSM.C';
end
I get "Undefined function or variable 'Yins'" as the error message, when I run the loop. Following message is also displayed:
Error in (line 67): [EstMdlSSM,params] = estimate(Mdl,Yins,param0,'Display','off','options',options,'Univariate',true);
Caused by: Failure in user-supplied function evaluation.
The VAR seems to work fine inside the loop. Can anyone please explain where I am going wrong here.
Thanks, Vineet

Respuestas (0)

Categorías

Más información sobre DSP Algorithm Acceleration en Help Center y File Exchange.

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by