🐛 Enable analytic_derivation for csminwel

Requires column vector output
kalman-mex
Johannes Pfeifer 2023-09-12 13:26:25 +02:00
parent 497c6bd1b1
commit 3895da48a1
2 changed files with 5 additions and 5 deletions

View File

@ -74,7 +74,7 @@ if strcmp(options_mom_.mom.mom_method,'GMM') || strcmp(options_mom_.mom.mom_meth
df = nan(size(oo_.mom.data_moments,1),length(xparam));
end
else
df = nan(1,length(xparam));
df = nan(length(xparam),1);
end
end
end
@ -284,9 +284,9 @@ if strcmp(options_mom_.mom.mom_method,'GMM') || strcmp(options_mom_.mom.mom_meth
df(:,jp) = dresiduals;
end
else
df(:,jp) = dresiduals'*residuals + residuals'*dresiduals;
df(jp,1) = dresiduals'*residuals + residuals'*dresiduals;
if options_mom_.mom.penalized_estimator
df(:,jp)=df(:,jp)+(dxparam1(:,jp))'/oo_.mom.prior.variance*(xparam-oo_.mom.prior.mean)+(xparam-oo_.mom.prior.mean)'/oo_.mom.prior.variance*(dxparam1(:,jp));
df(jp,1)=df(jp,1)+(dxparam1(:,jp))'/oo_.mom.prior.variance*(xparam-oo_.mom.prior.mean)+(xparam-oo_.mom.prior.mean)'/oo_.mom.prior.variance*(dxparam1(:,jp));
end
end
end

View File

@ -263,7 +263,7 @@ switch minimizer_algorithm
Verbose = 0;
end
% Set flag for analytical gradient.
if options_.analytic_derivation
if options_.analytic_derivation || (isfield(options_,'mom') && options_.mom.analytic_jacobian==1)
analytic_grad=1;
else
analytic_grad=[];
@ -276,7 +276,7 @@ switch minimizer_algorithm
if isempty(prior_information) %mr_hessian requires it, but can be NaN
prior_information.p2=NaN(n_params,1);
end
if options_.analytic_derivation
if options_.analytic_derivation
old_analytic_derivation = options_.analytic_derivation;
options_.analytic_derivation=-1; %force analytic outer product gradient hessian for each iteration
analytic_grad=1;