Bayesian Non-linear SSM with time varying coefficients
I have question about using ‘bnlssm’ object when the problem involves time-varying coefs. Per this documentation https://www.mathworks.com/help/econ/bnlssm.html , bnlssm allows the transition matrix to be a nonlinear function of the past values of the state vector, while also being time-varying –, i.e. A_t(x_{t-1}). However the documentation contains an example of the parameter mapping function for a fixed coef. case only:
function [A,B,C,D,Mean0,Cov0,StateType] = paramMap(theta)
A = @(x)blkdiag([theta(1) theta(2); 0 1],[theta(3) theta(4); 0 1])*x;
B = [theta(5) 0; 0 0; 0 theta(6); 0 0];
C = @(x)log(exp(x(1)-theta(2)/(1-theta(1))) + …
exp(x(3)-theta(4)/(1-theta(3))));
D = theta(7);
Mean0 = [theta(2)/(1-theta(1)); 1; theta(4)/(1-theta(3)); 1];
Cov0 = diag([theta(5)^2/(1-theta(1)^2) 0 theta(6)^2/(1-theta(3)^2) 0]);
StateType = [0; 1; 0; 1]; % Stationary state and constant 1 processes
end
Here, A and C are recognised as function handles and show the dimension of 1-by-1 when [A,B,C,D]=paramMap(theta) is run with a given theta. This does not prevent filter/smooth from returning the states estimates, as the function handles become m-by-m matices when the function handles are evaluated.
However, whenever I try replaceing A with a cell array, e.g.:
A=cell(T,1);
for t=1:T
A{t} = @(x)blkdiag([theta(1) theta(2); 0 1],[theta(3) theta(4); 0 1])*x;
end
bnlssm.fixcoeff throws an error that the dimensions of Mean0 are expected to be 1, per validation step in lines 700-707 of ‘bnlssm.m’:
if iscellA; At = A{1};
else; At = A; end
numStates0 = size(At,2);
if
isscalar(mean0)
mean0 = mean0(ones(numStates0,1),:);
elseif
~isempty(mean0)
mean0 = mean0(:);
validateattributes(mean0,{‘numeric’},{‘finite’,’real’,’numel’,numStates0},callerName,’Mean0′);
end
Q: Is it just overlook by MathWorks programmers and creating local verions of bnlssm/filter/smooth with that validation step removed is a viable pathway forward, or is it intentional because ‘bnlssm’ was in fact designed to handle only the time-invariant coef. case correctly?I have question about using ‘bnlssm’ object when the problem involves time-varying coefs. Per this documentation https://www.mathworks.com/help/econ/bnlssm.html , bnlssm allows the transition matrix to be a nonlinear function of the past values of the state vector, while also being time-varying –, i.e. A_t(x_{t-1}). However the documentation contains an example of the parameter mapping function for a fixed coef. case only:
function [A,B,C,D,Mean0,Cov0,StateType] = paramMap(theta)
A = @(x)blkdiag([theta(1) theta(2); 0 1],[theta(3) theta(4); 0 1])*x;
B = [theta(5) 0; 0 0; 0 theta(6); 0 0];
C = @(x)log(exp(x(1)-theta(2)/(1-theta(1))) + …
exp(x(3)-theta(4)/(1-theta(3))));
D = theta(7);
Mean0 = [theta(2)/(1-theta(1)); 1; theta(4)/(1-theta(3)); 1];
Cov0 = diag([theta(5)^2/(1-theta(1)^2) 0 theta(6)^2/(1-theta(3)^2) 0]);
StateType = [0; 1; 0; 1]; % Stationary state and constant 1 processes
end
Here, A and C are recognised as function handles and show the dimension of 1-by-1 when [A,B,C,D]=paramMap(theta) is run with a given theta. This does not prevent filter/smooth from returning the states estimates, as the function handles become m-by-m matices when the function handles are evaluated.
However, whenever I try replaceing A with a cell array, e.g.:
A=cell(T,1);
for t=1:T
A{t} = @(x)blkdiag([theta(1) theta(2); 0 1],[theta(3) theta(4); 0 1])*x;
end
bnlssm.fixcoeff throws an error that the dimensions of Mean0 are expected to be 1, per validation step in lines 700-707 of ‘bnlssm.m’:
if iscellA; At = A{1};
else; At = A; end
numStates0 = size(At,2);
if
isscalar(mean0)
mean0 = mean0(ones(numStates0,1),:);
elseif
~isempty(mean0)
mean0 = mean0(:);
validateattributes(mean0,{‘numeric’},{‘finite’,’real’,’numel’,numStates0},callerName,’Mean0′);
end
Q: Is it just overlook by MathWorks programmers and creating local verions of bnlssm/filter/smooth with that validation step removed is a viable pathway forward, or is it intentional because ‘bnlssm’ was in fact designed to handle only the time-invariant coef. case correctly? I have question about using ‘bnlssm’ object when the problem involves time-varying coefs. Per this documentation https://www.mathworks.com/help/econ/bnlssm.html , bnlssm allows the transition matrix to be a nonlinear function of the past values of the state vector, while also being time-varying –, i.e. A_t(x_{t-1}). However the documentation contains an example of the parameter mapping function for a fixed coef. case only:
function [A,B,C,D,Mean0,Cov0,StateType] = paramMap(theta)
A = @(x)blkdiag([theta(1) theta(2); 0 1],[theta(3) theta(4); 0 1])*x;
B = [theta(5) 0; 0 0; 0 theta(6); 0 0];
C = @(x)log(exp(x(1)-theta(2)/(1-theta(1))) + …
exp(x(3)-theta(4)/(1-theta(3))));
D = theta(7);
Mean0 = [theta(2)/(1-theta(1)); 1; theta(4)/(1-theta(3)); 1];
Cov0 = diag([theta(5)^2/(1-theta(1)^2) 0 theta(6)^2/(1-theta(3)^2) 0]);
StateType = [0; 1; 0; 1]; % Stationary state and constant 1 processes
end
Here, A and C are recognised as function handles and show the dimension of 1-by-1 when [A,B,C,D]=paramMap(theta) is run with a given theta. This does not prevent filter/smooth from returning the states estimates, as the function handles become m-by-m matices when the function handles are evaluated.
However, whenever I try replaceing A with a cell array, e.g.:
A=cell(T,1);
for t=1:T
A{t} = @(x)blkdiag([theta(1) theta(2); 0 1],[theta(3) theta(4); 0 1])*x;
end
bnlssm.fixcoeff throws an error that the dimensions of Mean0 are expected to be 1, per validation step in lines 700-707 of ‘bnlssm.m’:
if iscellA; At = A{1};
else; At = A; end
numStates0 = size(At,2);
if
isscalar(mean0)
mean0 = mean0(ones(numStates0,1),:);
elseif
~isempty(mean0)
mean0 = mean0(:);
validateattributes(mean0,{‘numeric’},{‘finite’,’real’,’numel’,numStates0},callerName,’Mean0′);
end
Q: Is it just overlook by MathWorks programmers and creating local verions of bnlssm/filter/smooth with that validation step removed is a viable pathway forward, or is it intentional because ‘bnlssm’ was in fact designed to handle only the time-invariant coef. case correctly? transferred MATLAB Answers — New Questions