Method of moments using genetic optimization

17 views (last 30 days)
I am trying to calibrate a model using simulated method of moments. I have a function f_SMM that calculates the model moments and sets up the objective function as follows:
function out = f_SMM(x)
global datamomvec datacovmat
....
momvec = zeros(length(datamomvec),1);
momvec(1) = 1.01;
momvec(2) = 1.0436;
momdiffvec = momvec - datamomvec;
SMMobj = (momdiffvec')*(datacovmat\momdiffvec); %criteria t be minimized
out = momvec
end
In my main.m I have the follows:
global datamomvec datacovmat
datamomvec = zeros(2,1);
datamomvec(1) = 1.287198;
datamomvec(2) = 14.17697;
datacovmat = eye(length(datamomvec));
xval(1) = .2; %the parameter to be claibrated
Nmom = length(datamomvec);
Nparam = length(xval);
%%SMM Optimization
lb = zeros(Nparam,1);
ub = lb;
lb(1) = .05; ub(1) = 1;%theta
lb_ub = [lb ub];
gaopts = gaoptimset('PopulationSize',50);
xval = ga(@(x)f_SMM(x),length(xval),[],[],[],[],lb,ub,[],gaopts);
I keep getting the following error:
Error using makeState (line 61)
Your fitness function must return a scalar value.
Error in galincon (line 22)
state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ga (line 402)
[x,fval,exitFlag,output,population,scores] =
galincon(FitnessFcn,nvars, ...
Error in wrapper_capstr (line 57)
xval = ga(@(x)f_SMM(x),length(xval),[],[],[],[],lb,ub,[],gaopts);
I tired to set my out to SMMobj. But that does nothing in terms of optimization. I am not sure how to best set my optimization to calibrate the model

Answers (1)

Walter Roberson
Walter Roberson on 20 Jan 2023
You have multiple model moments, and you are returning the vector of modeled values from your function f_SMM. However, ga() can only deal with scalar functions.
If you have multiple values being independently tuned, that is a "multi-objective optimization", such as is handled by gamultiobj() . gamultiobj() would look for pareto fronts -- places where no value can be made better without making another one worse (which is to say, local minima in the curvature)
If you want to do some kind of overall "best fit" then you need to change your f_SMM to return a scalar. For example you could have it return the sum of squares of differences between the modeled values and the known values.
  2 Comments
Prerna Mishra
Prerna Mishra on 20 Jan 2023
I tried returning SMMobj, the distance measure between the model moments and the data moments. WHile that worked, it did not optimiza at all even after many iterations. Is returning SMMobj right?
Walter Roberson
Walter Roberson on 20 Jan 2023
I would suggest testing f_SMM on a few different inputs, to be sure that it returns different numbers (and not, for example, inf or nan). Be sure to initialize the global variables before you do that however.
Better yet would be not to use global variables.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!