Optimization of 4 variables by minimizing RMSE error as an objective function using fminsearch

23 visualizaciones (últimos 30 días)
Hi all, im searching a way to optimize my objective function (RMSE) by using fminsearch. I have 4 variables: a, b, c & d.
Also, I have 23 simple equations that have to be replaced with the values a, b, c and d (these are the values to optimize).
Then a 1x23 column is created which I call CFPPi with the results of these values.
The next instruction is to create a 23 x69 matrix with the following instruction: prediction = CFPPi. * biodiesel_composition (biodiesel_composition is a 23x69 database).
Then I create a 1 x 69 row by doing the sum of each prediction column using the following operation biodisel_cfpp = sum (prediction, 1).
Lastly, I have another row of 1 x69, called experimental_value. These are the values that I want to approach by optimizing a, b, c and d and these 4 variables could be any random number that helps to minimize the error.
The main purpose is to make the RMSE error as small as possible. I did the above on Excel' solver using GNR nonlinear method and the results were pretty good but i want to double check in matlab if the optimization could be better. Can anyone suggest a solution?
Thanks in advance for your valuable help :)
syms a b c d
% 23 equiations:
c6=1*a+4*b+1*d;
c8=1*a+6*b+1*d;
c10=1*a+8*b+1*d;
c12=1*a+10*b+1*d;
c14=1*a+12*b+1*d;
c14_1=1*a+10*b+2*c+1*d;
c15=1*a+13*b+1*d;
c16=1*a+14*b+1*d;
c16_1=1*a+12*b+2*c+1*d;
c17=1*a+15*b+1*d;
c17_1=1*a+13*b+2*c+1*d;
c18=1*a+16*b+1*d;
c18_1=1*a+14*b+2*c+1*d;
c18_2=1*a+12*b+4*c+1*d;
c18_3=1*a+10*b+6*c+1*d;
c20=1*a+18*b+1*d;
c20_1=1*a+16*b+2*c+1*d;
c20_2=1*a+14*b+4*c+1*d;
c20_4=1*a+10*b+8*c+1*d;
c22=1*a+20*b+1*d;
c22_1=1*a+18*b+2*c+1*d;
c24=1*a+22*b+1*d;
c24_1=1*a+20*b+2*c+1*d;
%%%%%%% with the 23 equations above, a column 23 x 1 is created:
CFPPi=[c6;c8;c10;c12;c14;c14_1;c15;c16;c16_1;c17;c17_1;c18;c18_1;c18_2;c18_3;c20;c20_1;c20_2;c20_4;c22;c22_1;c24;c24_1];
%%% the column above is multiplied with a matrix of 23x63 (biodiesel_composition) data base and it creates a new matrix.
prediction=CFPPi.*biodiesel_composicion;
% Lately each column of the the prediction matrix is sum to create a row of 1x69
biodisel_cfpp=sum(prediccion,1);
% The rmse function is:
function rmse (experimental_values,biodisel_cfpp)
r = sqrt(sum((experimental_values(:)-biodisel_cfpp(:)).^2/numel(experimental_values)))
end
%so when a tried to optimize rmse, the following i got the following messaje:

Respuesta aceptada

Thiago Henrique Gomes Lobato
Thiago Henrique Gomes Lobato el 26 de Abr. de 2020
Some points:
  1. Your rmse function is not returning any value
  2. You need to pass a function to the optimization function that takes only the variables that can be optimized
  3. Since you're optimizing a,b,c,d all the calculations related to those variables should stay in the optimization function
Taking those points in consideration you can do something like this:
x0 = [1,1,1,1]; % you can give a reasonable value here
[x,fval] = fminsearch(@(x)rmse(x,experimental_values),x0) % I', assuming experimental_values is on your workspace
% The rmse function is:
function r = rmse (x,experimental_values)
a = x(1);
b = x(2);
c = x(3);
d = x(4);
c6=1*a+4*b+1*d;
c8=1*a+6*b+1*d;
c10=1*a+8*b+1*d;
c12=1*a+10*b+1*d;
c14=1*a+12*b+1*d;
c14_1=1*a+10*b+2*c+1*d;
c15=1*a+13*b+1*d;
c16=1*a+14*b+1*d;
c16_1=1*a+12*b+2*c+1*d;
c17=1*a+15*b+1*d;
c17_1=1*a+13*b+2*c+1*d;
c18=1*a+16*b+1*d;
c18_1=1*a+14*b+2*c+1*d;
c18_2=1*a+12*b+4*c+1*d;
c18_3=1*a+10*b+6*c+1*d;
c20=1*a+18*b+1*d;
c20_1=1*a+16*b+2*c+1*d;
c20_2=1*a+14*b+4*c+1*d;
c20_4=1*a+10*b+8*c+1*d;
c22=1*a+20*b+1*d;
c22_1=1*a+18*b+2*c+1*d;
c24=1*a+22*b+1*d;
c24_1=1*a+20*b+2*c+1*d;
%%%%%%% with the 23 equations above, a column 23 x 1 is created:
CFPPi=[c6;c8;c10;c12;c14;c14_1;c15;c16;c16_1;c17;c17_1;c18;c18_1;c18_2;c18_3;c20;c20_1;c20_2;c20_4;c22;c22_1;c24;c24_1];
%%% the column above is multiplied with a matrix of 23x63 (biodiesel_composition) data base and it creates a new matrix.
prediction=CFPPi.*biodiesel_composicion;
% Lately each column of the the prediction matrix is sum to create a row of 1x69
biodisel_cfpp=sum(prediccion,1);
r = sqrt(sum((experimental_values(:)-biodisel_cfpp(:)).^2/numel(experimental_values)));
end

Más respuestas (0)

Categorías

Más información sobre Solver Outputs and Iterative Display en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by