Minimizing a set of known values?

4 次查看(过去 30 天)
Harvey Rael
Harvey Rael 2018-7-26
Hi All,
I can attach the code I am working on if it helps but my question is more general than that. I am looking to minimize an output by optimizing one of the input variables, using a genetic algorithm. The catch is, I know the output variable is going to be a 20x50 array and one of those values is a minimum. I want to find the minimum of the output variable by optimizing the input variable but I keep getting the error message "Unable to perform assignment as left side is 1by1 and right side is 20x50". Any idea as to why I keep getting that, or would you need the code?
Edit: I have attached a zip file with all the files you need. They all need to be on the path. "expoSinWrapper" is the objective function needing to be minimized, and tof_1 and k2 are the variables that need to be optimised. "attempt_2" is the ga implementation, and "mapvariables" is just some mapping I am attempting. There is a lot of fluff from combinations I have tried to fix my own error, that I have commented out. In layman's terms I am trying to minimize M_Fuel, by optimising a combination of k2 and tof_1. I hope that is clear and helpful. The newest error is the assignation to k2,
k2 = x(2)
it says index exceeds array bounds, but from the documentation I thought you were allowed to do that for multi variable optimisation?
EDIT 2: I fixed the problem, it was in the initialisation of the GA. Now the problem is that the fval being returned is the abnormally high one I set for errors in the objective function, meaning there isn't an optimisation occuring. Apologies for the messy question. Can anyone help?
  3 个评论
Aquatris
Aquatris 2018-7-26
Optimization algorithms expect a cost function that results in a scalar value, not an array. Since your function outputs 20x50 array, and GA expects a scalar, that might be the problem you are having. If you are only interested in the minimum value, just change your function to be optimized to output the minimum value within the 20x50 array.
Harvey Rael
Harvey Rael 2018-7-27
Ok, I've fixed it so that the cost function is a scalar but I am still getting wrong values. The GA is returning an fval that is the arbitrarily high one I am setting in the case of an error. I will edit my question to include the scripts in a minute.

请先登录,再进行评论。

回答(0 个)

类别

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

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by