MATLAB: Constraints and bounds in genetic algorithms

boundsconstraintsga

1) If my function has no constraints, do I have to state something like NIL for constraints or need not write anything about constraints?
2) To run GA, is it compulsory to use “InitialPopulation” command to generate the initial population?
3) What is the meaning of the following lines?
a) rand(20, 2); –> is to randomly generate a 20 by 2 matrix
b) 10*rand(20, 2) means what?
c) repmat([10, 30] , 20, 1); –> means what?
Can I have more simple examples of the usage of repmat? (besides those in the documentation, because I can’t understand those examples).
d) what does the combination of rand and repmap mean in the following line?
initpop = 10*rand(20, 2) + repmap ([10, 30], 20, 1);
4) Rastrigin’s function did not set bounds. How does GA know the range of x and y values during crossover and mutation?
5) When we run Rastrigin's function with GA, is it possible to produce the output exactly as 0 since it is the minimum value? I tried to run it a few times, each time the output is only approximately 0 (e.g. 0.00123, 0.0456 etc) why is it so?
6) If I know the minimum value of my function, what adjustment I need to do in order to produce the exact minimum value? Besides tuning those parameters in the options, do I just keep running GA repeatedly until I get the minimum value? What conclusion can I draw once I achieved the actual known minimum value?
That say, if I don't the minimum value, how do I know I have achieved the minimum?

Best Answer

1)You can call GA like this
x = ga(fitnessfcn,nvars)
in which case all other inputs will take default values. Or, if you want to specify IntCon or options, you can do
x = ga(fitnessfcn,nvars,[],[],[],[],[],[],[],IntCon,options)
so that just the constraints will take their default values.
2) No.
3) What is the meaning of the following lines?
a) is to randomly generate a 20 by 2 matrix Yes
b) The same as (a) multiplied by 10.
c) It will copy [10,30] tile-wise 20 times vertically. Another example is repmat([1 2;3 4],2,3). It should be pretty easy to figure out REPMAT through some experimentation.
d) It's a way of adding a bias of [10,30] to every row of the random 20x2 first term. However, it's an outdated way to do it. You should use BSXFUN instead
initpop= bsxfun(@plus, 10*rand(20,2), [10,30])
4) According to the doc, the PopInitRange option controls the initial range. Presumably, the range then evolves during mutation.
5) Iterative algorithms like GA, but also more generally, are asymptotic. They try to converge to the solution, but rarely achieve it exactly, even if the solution is exactly representable in floating point. However, there are various tolerance parameters that control stopping, which you can read about here
6) Knowing the minimum value will not help you search for the minimizing variables. You can know whether you've found a local minimum by checking optimality conditions, e.g., if the gradient is zero in smooth, unconstrained problems. Unless you know the global minimum value, you can never know/guarantee whether you've successfully found the global min.