Dear,
I always struggle to understand code for optimization problems.
Hence I kindly ask for your help with following task:
The task is to optimize a set of calibration coefficients, such that a calculated value is as close as
possible to a reference…in other words: The distance between the calculated value and the reference value is minimal.
There are some start values for the calibration coefficients and and also some upper and lower bounds for them.
Also a stop criteria is defined and we want to introduce a max number of iteration steps
// start values for calib coeff
calibCoeff_0 = [ t1_0, t2_0, p1_0, p2_0, p3_0];
// upper bounds for calib coeff
UBDS = [ t1_up, t2_up, p1_up, p2_up, p3_up,];
// lower bounds for calib coeff
LBDS = [ t1_lo, t2_lo, p1_lo, p2_lo, p3_lo,];
// stop criteria ... end optimization if the result of myfunc() < STOP_CRIT
STOP_CRIT = 1*10^(-6)
// maximal iteration steps
MAX_ITER_STEP = 6000;
// library function to calculate P & T values based on calibCoeff and raw values
[P, T] = calcValues(calibCoeff, p_Raw, t_Raw);
I think a function is necessary that compares the result using the actual coefficients against the reference value
// function to compare result with actual calibCoeff against reference value
// "res" shall be minimized
function [f, g, ind] = myfunc([pRaw tRaw refVal], ind, parameters)
// assumption [pRaw tRaw refVal] = x from help page ...is this correct(?)
// calculate P and T based on current calibCoeff (parameters)
[P, T] = calcValues(parameters, pRaw, tRaw);
// calcluate difference from reference
res = (refVal - P)^2
// assumptions ... is that correct(?)
f = P;
g = res;
endfunction
Now: I GUESS that myfunc() is what is normally called the cost function. As this needs a set of parameters I would follow the approach from the help page of using a list
// Store the parameters
parameters = tlist ([
"T_MYPARAMS"
"t1"
"t2"
"p1"
"p2"
"p3"
]);
parameters.t1 = t1;
parameters.t2 = t2;
parameters.p1 = p1;
parameters.p2 = p2;
parameters.p3 = p3;
costf = list (myfunc, parameters);
I GUESS the optim call would look similar to this….
[fopt, xopt] = optim (costf, calibCoeff, "b", LBDS, UBDS, calibCoeff_0, MAX_ITER_STEP, STOP_CRIT)
However:
As you may have realized I am a bit confused and any help would be appreciated. e.g.: would xopt be the set of optimized calibCoeff (parameters) ?
Thank you,
Philipp