Method of moments using genetic optimization
35 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
Walter Roberson
2023-1-20
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 个评论
Walter Roberson
2023-1-20
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Genetic Algorithm 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!