Multiple Parameters in fmincon

3 visualizaciones (últimos 30 días)
M R
M R el 18 de En. de 2021
Editada: Matt J el 19 de En. de 2021
I have a fairly simple model that looks as follows:
, where α is a constant, and X and β are p x 1 vectors.
I have given data for my dependent variable (y) and two covariates ('cov1' and 'cov2'). My approach so far has been the following:
% Data
y = [20, 21, 24, 26, 27, 28, 32, 37, 38, 39, 40, 45, 43, 40, 38];
cov1 = [70, 71, 74, 78, 78, 81, 83, 84, 86, 89, 91, 91, 92, 96, 91];
cov2 = [101, 101, 104, 108, 108, 110, 111, 114, 115, 117, 117, 118, 117, 119, 120];
% initial values
param_init = [0, 0, 0];
% function
y_model = @(p) p(1) + p(2).*cov1 + p(3).*cov2;
objective = @(p) sqrt(mean((y - y_model(p)).^2));
% optimization
[param_opt, fval] = fmincon(objective, param_init)
My goal is to minimize the RMSE between the observed y and my y_model values. At the moment I have specified three parameters for this purpose.
However, it would be interesting to know how I can specify that β is a p x 1 vector without specifying two separate parameters in my function ? I am not sure if this will work though?

Respuestas (1)

Matt J
Matt J el 19 de En. de 2021
Editada: Matt J el 19 de En. de 2021
I'm not sure why you are using fmincon for something that has a simple, non-iterative solution:
C=[cov1(:).^0,cov1(:),cov2(:)];
beta = C \ y(:);
If you will eventually be adding in linear constraints on your beta(i), then you should use lsqlin.
If you will eventually be adding in nonlinear (and possibly also linear) constraints, then you can set up fmincon as,
C=[cov1(:).^0,cov1(:),cov2(:)];
objective = @(p) norm(C*p(:)-y(:)).^2;
[beta_opt, fval] = fmincon(objective, beta_init,A,b,Aeq,beq,lb,ub,nonlcon);
  2 comentarios
M R
M R el 19 de En. de 2021
@Matt J thanks for your answer. This represents only a minimal working example and I will add constraints etc. Concerning the setup you described in fmincon, I have a hard time following you. In my example I get y_model by optimizaiton. In your model you assume it as given? It also seems that the dimensions of the two vectors to be compared do not fit? Can you give me a little advice on what I am missing here so that I can ultimately evaluate the RMSE between my given y and the y obtained from my model?
Matt J
Matt J el 19 de En. de 2021
Editada: Matt J el 19 de En. de 2021
Sorry, everywhere I had put "y_model", I really meant to have just "y".
The vectorized form of y_model that you are asking for, which doesn't require any explicit indexing of the parameters, is just,
y_model=@(p) C*p(:)

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by