How can I use some of the class properties as optimization parameters while keeping others fixed ?

2 次查看(过去 30 天)
Hi,
I have a class that contains the model parameters required to model a fuel cell. While modeling the fuel cell, I pass an object instance of this class to the functions where these parameters are used for calculations. Now, I want to use same model/functions and perform optimization/calibration on fuel cell. This would require me to vary some of the model parameters while keeping others as fixed vlaues. The split between the number of fixed and varying parameters can also change.
As per my limited understanding, If I pass the object with all the properties to the optimizer function then all the parameters would be varied. So, my question is: how can I divide the properties of the class object into two sets: fixed and varying and then pass them to the optimizer.
I have looked into the answer at link below that highlights the method of using wrapper functions. But I am still not sure how do apply this idea when the parameter set is contained inside a class object.
Thanks.
  6 个评论
Abhijay Awasthi
Abhijay Awasthi 2020-6-13
ahh, Ok. Thank you very much for this clarification. Would you have any tips for me on how to use parameters in this class object as optimization handles? Any workaround by creating numeric arrays ?
Abhijay Awasthi
Abhijay Awasthi 2020-6-13
Ameer, Thanks for replying. I am still developing the code for using this class inside an optimizer. But I think, based on Walter's answer, this approach would not work.

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2020-6-13
The split between the number of fixed and varying parameters can also change.
For each different combination, write a accessory function that accepts and object and a vector of values, and splits the values in pieces and sets the object properties to the extracted parts and returns the resulting object.
Then write an objective function that is parameterized to accept a vector of values and the "prototype" object and a function handle (to the accessory function.) The objective function should pass the vector of values and the prototype to the accessory function, getting back an object, and then the objective function should calculate the "cost" of that particular object.
As far as the optimization functions are concerned, they are calling a function that accepts a vector of values. The anonymous function captures the prototype and the accessory function handle, calls the accessory function to build the new object, and costs that out.
Depending on your needs, it might be possible to construct just one accessory function that takes a data structure that describes how to do the splitting, such as a struct with fields named for properties to set, and whose values are indices of values to take from the x vector and pass into the set() routine

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Genetic Algorithm 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by