Model calibration in Matlab: find minimum RMSE

1 回表示 (過去 30 日間)
yoni verhaegen
yoni verhaegen 2018 年 6 月 4 日
コメント済み: Jeff Miller 2022 年 12 月 6 日
Hi all,
I have a model that runs a mass balance profile for a glacier (i.e. the net result between melt and snow accumulation). However, I have a set of 7 variables to calibrate the model. I was wondering if there is some kind of small program I can write to run the model several times with all different values for the parameters within a certain range, in order to find the minimum RMSE. For example, parameter 1 from 0.4 to 0.6, parameter 2 from 0.34 to 0.42, etc. I was thinking about a random walk method but it is hard to write these kind of things. It would be very much appreciated. Can anybody help me getting started?
Thanks!

回答 (1 件)

Jeff Miller
Jeff Miller 2018 年 6 月 4 日
編集済み: Jeff Miller 2022 年 12 月 6 日
It seems like you have to start by writing the function to compute RMSE for a given set of parameter values, e.g.,
function thisRMSE = myRMSE(x)
% x is a vector of 7 parameter values.
% thisRMSE is the RMSE for those values.
% ...
end
After you have that, you can use fminsearch, which will probably do a better job of finding the minimum RMSE than a random walk.
StartingGuess = [0.5, 0.38, ...]; % Your initial best-guesses for the 7 parameter values.
[BestGuess, BestRMSE] = fminsearch(@myRMSE,StartingGuess);
If the solution space is nasty, there is a good chance that fminsearch will get caught in a local minimum (as too would your random walk process). The only thing you can do about that is to run fminsearch repeatedly from lots of different starting guess vectors, keeping whichever final 'BestGuess' really produces the lowest RMSE. You could even do that in a loop, generating the different starting guesses randomly.
HTH
  4 件のコメント
Pablo Cordoba
Pablo Cordoba 2022 年 12 月 6 日
Hello @Jeff Miller, I am trying to use the fminsearch function as you explained to find the minimum RMSE for a model output but I get an error:
The starting guess are some random parameter values that I have chosen to test the fminsearch function.
StartingGuess = [1,0.2,30,445,5];
And I obtain my RMSE like this:
sqrdError = (target_data{:,2} - model_data{1:end,2}).^2 ; % Squared Error
RMSE = sqrt(mean(sqrdError)); % Root Mean Squared Error
Then I run the fminsearch function like you did:
[newGuess, newRMSE] = fminsearch(RMSE,StartingGuess);
But when I run it I get this error that I don't know how to fix:
Error using fcnchk (line 107)
FUN must be a function, a valid character vector expression, or an inline function object.
Error in fminsearch (line 174)
funfcn = fcnchk(funfcn,length(varargin));
Error in modelCalibration (line 56)
[newGuess, newRMSE] = fminsearch(RMSE,StartingGuess);
Jeff Miller
Jeff Miller 2022 年 12 月 6 日
The first parameter for fminsearch has to be a function, but it looks like you are trying to give it a computed value. Take the code that you used to compute model_data and RMSE (from any arbitrary set of parameters) and move that code into a separate function that can be called by fminsearch. fminsearch will call your function with lots of different parameter combinations and try to find the best one (min RMSE).
See https://au.mathworks.com/help/matlab/ref/fminsearch.html and look at the example "Minimize a Function Specified by a File"

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by