Reputation: 239
I have a small model that I use to estimate the growth of a population of fungi given the environmental condition. The model, practically, is a MATLAB function in the following form:
growth=myfunction(envdata,params)
where growth
is how much my fungi grow (duh!), envdata
is a matrix of enviromental variables (one row per timestep, each column is a different variable such as temperature, humidity, etc. etc. etc.) and params
are the parameters of my model. The latter are the ones that I would like to optimize and they include such things as the (unknown) initial fungal population, maximum fungi that can exist as a certain time, etcetera etcetera.
At the same time I have a vector of growth measured in the lab (my observations) and my objective is now to fit my model to the observations by varying the input parameters.
My natural answer would have been to use something such as fminsearch
, but it has no option of using an observation vector as a minimum. Or am I wrong?
Upvotes: 0
Views: 108
Reputation: 47392
You want to fit the difference between your observations and the model's fitted growth rate as closely as possible but, as you pointed out, fminsearch
doesn't allow you to use a target vector.
The solution is to define a wrapper function that defines the thing you are trying to minimize (often called the loss). One popular loss is the mean-square error,
MSE(x, y) = Σ (x - y)2
so you could define, for example,
function loss = objectiveFun(observations, envdata, params)
growth = myfunction(envdata, params);
loss = sum((observation - growth).^2); // or your favorite loss function
end
and then run
paramsInit = 0; // whatever initial value you have for params
paramsOpt = fminsearch(@(x) objectiveFun(observations, envdata, x), paramsInit);
Upvotes: 1