Help with Surrogate Modeling Multivariable Objective Function

Hi,
I am trying to figure out how to create an objective function with multiple variable inputs. The objective function needs to be the energy input (Ein) into a system as a function of L,A,and T. Right now I have the equation for the energy input (Ein) in terms of each of these variables. For instance:
Ein = L^2+L
Ein = A^2 +A
Ein = T^2 +T
My actual equation is more complex but just to give a general idea. I now want to create an objective function (Ein) as a function of L,A, and T by combining the 3 known equations. This is part of a general optimization problem where I want to find the optimal paramaters that maximize Ein. I was looking at surrogate modeling to create this new objective function but am not sure if it is able to handle my problem. Please let me know if you have any suggestions.
Thanks!

 Accepted Answer

Yes, you should be able to do that. Construct lb and ub vectors (mandatory!! and must be finite!) that are length() equal to the number of variables being optimized over. The objective function should then expect a vector of that length.
Internally the function can index the vector whenever needs, or it can assign the elements to meaningful variable names and use the names, whichever is easier. Indexing is typically easier for functions automatically generated from symbolic expressions; assigning to local variables is typically more readable.

7 Comments

I understand the ub and lb part. My function needs to have bounds of 0≤L≥5 45≤A≥80 0.5≤T≥1 so for lb I would put [0;45;0.5] and ub would be [5;80;1]. What I am struggling is how to input objconstr to include the known functions of L,A,and T.Surrogate optimization has the following syntax:
x=surrogateopt(objconstr,lb,ub)
However for objconstr, do I just make a new function that has 3 inputs (L,A,T) and one output? So something like:
function [Ein] = objconstr(L,A,T)
Ein = L^2+L
Ein = A^2 +A
Ein = T^2 +T
end
then the final script would read
lb = [0;45;0.5]
ub = [5;80;1]
x=surrogateopt(objconstr,lb,ub)
However, when I do this I get the error "Error using surrogateopt>createController (line 315)
Objective function must be a function handle."
The objective function should then expect a vector of that length.
Internally the function can index the vector whenever needs,
function [Ein] = objconstr(LAT)
Ein = LAT(1)^2 + LAT(1);
Ein = LAT(2)^2 + LAT(2);
Ein = LAT(3)^2 + LAT(3);
end
or it can assign the elements to meaningful variable names and use the names, whichever is easier.
function [Ein] = objconstr(LAT)
L = LAT(1); A = LAT(2); T = LAT(3);
Ein = L^2+L
Ein = A^2 +A
Ein = T^2 +T
end
However, remember that the output needs to be a scalar for the objective. The code you wrote does create a scalar for the objective, but it does so by overwriting the scalar in each step.
lb = [0;45;0.5];
ub = [5;80;1];
[x, fval] = surrogateopt(@objconstr,lb,ub)
Surrogateopt stopped because it exceeded the function evaluation limit set by 'options.MaxFunctionEvaluations'.
x = 1×3
0 45.0000 0.5000
fval = 0
function [Ein] = objconstr(LAT)
Ein = (LAT(1)^2 + LAT(1))*(LAT(2)^2 + LAT(2))*(LAT(3)^2 + LAT(3));
end
Thank you! I changed the function to
function [Ein] = objconstr(LAT)
Ein = (LAT(1)^2 + LAT(1))*(LAT(2)^2 + LAT(2))*(LAT(3)^2 + LAT(3));
end
to return one scalar (Ein). and the rest of the code to
lb = [0;45;0.5]
ub = [5;80;1]
x=surrogateopt(@objconstr,lb,ub)
and it is running.
Is the new objective function equivalent to what I was looking for?
I now want to create an objective function (Ein) as a function of L,A, and T by combining the 3 known equations.
It seems to me that if you have three input sources, that the total energy in the system would be the sum of the sources rather than the product of the sources ?
Question: Is it all the same to you if you increase the L by (say) 100 and decrease the A by 102, with you saying "That's a net decrease of 2, that's fine!" ? As compared to (for example) increasing the L component by 1 and decreasing the A by 2 for a net decrease of 1, but with the values kept more balanced?
It is common in such situations to use an objective that is a weighted sum of squares (with using equal weights to be common), so like
Ein = w1*(LAT(1)^2 + LAT(1)).^2 + w2*(LAT(2)^2 + LAT(2)).^2 + w3 * (LAT(3)^2 + LAT(3)).^2;
This allows you to adjust the relative importance of the factors, but keeps them more balanced.

Sign in to comment.

More Answers (0)

Categories

Products

Community Treasure Hunt

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

Start Hunting!