Hello everyone, I’m using cmaes.m to compute the posterior mode(cause csminwel.m can’t find the solution,matlab reports “smallest step still improving too slow, reversed gradient”). But I don’t know how to use cmaes.m, is there any example to help me better understand how to ues it? Thakns a lot !

What do you mean? You can trigger `cmaes.m`

using `mode_compute=9`

.

Dear prefessor,

Thank you for your reply . I’m estimating a regime switching DSGE, so I need to code by myself. I’m sorry to bothor you but I was wondering if you could help me with something.

I have tried cmaes.m, however the sulution is weired. Below is the code which I use to compute posterior mode,

H0 =0.2*ones(size(20,1),1);

cmaesOptions = cmaes;

cmaesOptions.LBounds = P.para(:,2);

cmaesOptions.UBounds = P.para(:,3);

[x_opt_hat, fhat, COUNTEVAL, STOPFLAG, OUT, BESTEVER] = cmaes(‘PostKer’,xini’,H0,cmaesOptions,block,m,P);

Where block is 1x24 double of 1,2,…,24(I have 24 parameters in total), m is the rise object, P is the parameter struct, which has parameter name/ parameter type/parameter value (initial value, lower bound, upper bound, mean and std). After running this code, it finishes super quicklly and reports

n=24: (6,13)-CMA-ES(w=[38 25 17 11 7 3]%, mu_eff=4.0) on function PostKer

Iterat, #Fevals: Function Value (median,worst) |Axis Ratio|idx:Min SD idx:Max SD

1 , 14 : 1.0000000000000e+08 +(0e+00,0e+00) | 1.04e+00 | 13:1.9e-01 5:1.9e-01

#Fevals: f(returned x) | bestever.f | stopflag (saved to variablescmaes.mat)

15: 1.00000000000e+08 | 1.00000000000e+08 | equalfunvals

mean solution: +4.3e+00 +3.3e-01 +4.0e-01 +5.4e-01 +3.5e+00 +3.8e-01 +9.0e-01 +7.5e-01 +5.8e-01 +8.0e-01 +1.3e-01 +1.5e-01 +6.1e-01 +2.1e+00 +2.5e-02 +9.0e-01 +9.6e-01 +1.9e+00 +1.0e+00 -3.5e-01 +2.3e-01 +4.4e-01 -5.7e-01 -4.2e-01

std deviation: 1.9e-01 1.9e-01 1.9e-01 1.9e-01 1.9e-01 1.9e-01 1.9e-01 1.9e-01 1.9e-01 1.9e-01 1.9e-01 1.9e-01 1.9e-01 1.9e-01 1.9e-01 1.9e-01 1.9e-01 1.9e-01 1.9e-01 1.9e-01 1.9e-01 1.9e-01 1.9e-01 1.9e-01

use plotcmaesdat.m for plotting the output at any time (option LogModulo must not be zero)

Then the output x_opt_hat is the same as xini. Below is the code which I use to compute posterior mode using csminwel, I mimic this code to call function cmaes

[realbig,xopt,~~,Hopt,~~,~~,~~] = csminwel(‘PostKer’,xini,Hini,,1e-5,500,0,block,m,P);

This code returns

Improvement on iteration 1 = 0.000000000

improvement < crit termination

smallest step still improving too slow, reversed gradient

I think I call the csminwel function correctly, but I still don not know what this report means. I wanna ask professor do I call the cmaes.m function correctly? What does the solution means after running cmaes.m and csminwel.m?Sorry to bothor you again, thanks in advance.

Best wishes!

Zhan

Check your initial values. The return value of `1.0000000000000e+08`

indicates an error code. Apparently, the code never moves away from that pathological point.