GA code problem in using options

I am using GA as a solver of my optimization problem. However, it gives me an error about options I use. o
ptions = optimoptions('ga','MaxGenerations',{10e5});
[x,fval] = ga(@obj_func,3,[],[],[],[],lb,ub,options);
The error I get is as follow:
Error using optimoptions (line 114)
Invalid solver specified. Provide a solver name or handle (such as 'fmincon' or
@fminunc).
Type DOC OPTIMOPTIONS for a list of solvers.
I have checked the option for GA and apparently, I am not using anything wrong. Anyone can help me with this? Thank you so much for the time.

 Respuesta aceptada

Alan Weiss
Alan Weiss el 19 de Oct. de 2018

2 votos

optimoptions was extended to ga in R2016a. If your MATLAB version is older than that, use gaoptimset. And, as Stephan said, do not put the value of MaxGenerations in curly braces.
Alan Weiss
MATLAB mathematical toolbox documentation

7 comentarios

Maryam
Maryam el 19 de Oct. de 2018
Thank you Alan for your helpful comment. You are right. When I use the options in the following format optimization goes through:
options = gaoptimset(@ga);
However, when I want to change something, and add to options I get the error as follow:
options = gaoptimset(@ga,'MaxGenerations',1e5);
[x, fval] = ga(@obj_func,3,[],[],[],[],lb,ub,[],options);
Error:
Error using gaoptimset (line 254)
Expected argument 1 to be a string parameter name or an options structure
created with GAOPTIMSET.
Error in complete_code (line 268)
options = gaoptimset(@ga,'MaxGenerations',1e5);
Matt J
Matt J el 19 de Oct. de 2018
You need to read the documentation for gaoptimset and learn its proper syntax.
Maryam
Maryam el 19 de Oct. de 2018
I totally have. "MaxGenerations" is one of the options there. Please see the link below:
Alan Weiss
Alan Weiss el 19 de Oct. de 2018
In particular, the correct syntax is
options = gaoptimset('MaxGenerations',1e5);
Alan Weiss
MATLAB mathematical toolbox documentation
Maryam
Maryam el 19 de Oct. de 2018
I have tried this one too, which gives me the following error:
Error using gaoptimset (line 289)
Unrecognized parameter name 'MaxGenerations'.
Error in complete_code (line 268)
options = gaoptimset('MaxGenerations',1e5);
Alan Weiss
Alan Weiss el 19 de Oct. de 2018
Editada: Alan Weiss el 19 de Oct. de 2018
Sorry, my oversight. The correct syntax, as documented, is
options = gaoptimset('Generations',1e5);
It would probably be easier for you not to use the current documentation, but instead to use the documentation for your version of MATLAB.
Alan Weiss
MATLAB mathematical toolbox documentation
Maryam
Maryam el 19 de Oct. de 2018
I have tried this and it is working. Thank you so very much for your patience with me.

Iniciar sesión para comentar.

Más respuestas (1)

Stephan
Stephan el 19 de Oct. de 2018
Editada: Stephan el 19 de Oct. de 2018
Hi,
this one does create a valid options object on my system:
options = optimoptions(@ga,'MaxGenerations',10e5);
[x,fval] = ga(@obj_func,3,[],[],[],[],lb,ub,options);
Note that the value should be a real integer: MaxGenerations Maximum number of iterations before the algorithm halts. Positive integer |{100*numberOfVariables} for ga, {200*numberOfVariables} for gamultiobj
The curly braces in the documentation tell you: Values in {} denote the default value.
There is a difference between both, because a cell array is not an integer:
>> a = 10e5
a =
1000000
>> b = {10e5}
b =
1×1 cell array
{[1000000]}
>> whos a b
Name Size Bytes Class Attributes
a 1x1 8 double
b 1x1 120 cell
Best regards
Stephan

2 comentarios

Maryam
Maryam el 19 de Oct. de 2018
I have used the exact same comments as you provided but I still get the same error.
Error using optimoptions (line 114)
Invalid solver specified. Provide a solver name or handle (such as 'fmincon' or
@fminunc).
Type DOC OPTIMOPTIONS for a list of solvers.
Error in complete_code (line 268)
options = optimoptions(@ga,'MaxGenerations',10e5);
I have also tried "fminunc" but I get the same error. I believe there is something wrong with using the option. Please help me if anyone knows what the problem is. Thank you, Stephan, for your help.
Stephan
Stephan el 19 de Oct. de 2018
Did you see Alans answer? Sometimes it is useful to provide the Matlab release used.

Iniciar sesión para comentar.

Categorías

Preguntada:

el 18 de Oct. de 2018

Comentada:

el 19 de Oct. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by