Issues with minimizing function using genetic algorithm.
Show older comments
I have an issue with trying to minimize the function in the code above using a genetic algorithm. The error I keep getting is shown below. mY call function is
M=[14000,15555,16000,17000,18000,19000;
14555,15555,16000,17555,18530,19000];
options = gaoptimset('InitialPopulation',M);
[x fval] = ga(@FuzzyForecast,6, options)
I would be glad if anyone could help.
Error using evalfismex
Illegal parameters in fisTriangleMf() --> a > b
Error in evalfis (line 83)
[output,IRR,ORR,ARR] = evalfismex(input, fis, numofpoints);
Error in FuzzyForecast (line 52)
u=evalfis(FLC_input,a);%evaluating output a.fis
Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11)
fcn_handle = @(x) fcn(x,FcnArgs{:});
Error in fcnvectorizer (line 13)
y(i,:) = feval(fun,(pop(i,:)));
Error in makeState (line 58)
Score =
fcnvectorizer(state.Population(initScoreProvided+2:end,:),FitnessFcn,1,options.SerialUserFcn);
Error in gaunc (line 40)
state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ga (line 356)
[x,fval,exitFlag,output,population,scores] = gaunc(FitnessFcn,nvars, ...
Caused by:
Failure in user-supplied fitness function evaluation. GA cannot continue.
Answers (1)
Walter Roberson
on 22 Sep 2018
You need to pass in linear inequalities that force your fis inputs to be sorted. For two variables near 1 that would look like
A = [1 -1]
b = -eps
16 Comments
Honey Adams
on 22 Sep 2018
The linear inequalities are arguments that are given to ga:
[x fval] = ga(@FuzzyForecast,6,A,b,options)
So your turn is to define A and b like Walter suggested and Call ga with this input. See the ga documentation for details.
What i can not help you with, is how to adapt Walters answer for your case, since i have no idea of fuzzy.
Honey Adams
on 22 Sep 2018
Stephan
on 22 Sep 2018
Walter wrote:
...linear inequalities that force your fis inputs to be sorted
See his example:
A = [1 -1]
b = -eps
That means:
1*x(1) -1*(2) < -eps
This inequality will only be true if
x(1) < x(2)
which means they are forced to be sorted.
This is how i understand the answer. So i would conclude that you need x in a way:
x(1) < x(2) < x(3) ... < x(6)
Your both initial populations are meeting this conditions.
Does this make sense for you?
Walter Roberson
on 22 Sep 2018
For 3 variables, A would be
[1 -1 0
0 1 -1]
Honey Adams
on 22 Sep 2018
Honey Adams
on 22 Sep 2018
Honey Adams
on 22 Sep 2018
Honey Adams
on 22 Sep 2018
Edited: Honey Adams
on 22 Sep 2018
Honey Adams
on 22 Sep 2018
Edited: Walter Roberson
on 22 Sep 2018
Honey Adams
on 22 Sep 2018
Walter Roberson
on 22 Sep 2018
You put the options in the slot reserved for the nonlinear constraint. You need one more [] before options.
Honey Adams
on 22 Sep 2018
Edited: Walter Roberson
on 22 Sep 2018
Walter Roberson
on 22 Sep 2018
"Numeric Rule Description
The final column specifies the antecedent fuzzy operator and corresponds to the Connection property of the rule."
According to the error message I am getting,
"Fuzzy connection operator must be 1 or 2, AND or OR, respectively."
In each row of your rules, the final column is 0, which is not either 1 or 2.
Your rules do not seem to make sense to me. The first four of them correspond to
1 "Input_enrol1 ==A1 => output_enrol1=B1 (1)"
2 "Input_enrol1 ==A1 => output_enrol1=B2 (1)"
3 "Input_enrol1 ==A3 => output_enrol1=B2 (1)"
4 "Input_enrol1 ==A3 => output_enrol1=B3 (1)"
The same input value implies two different output values? The second and fifth possible input value have no rule?
Honey Adams
on 23 Sep 2018
Walter Roberson
on 23 Sep 2018
If you only have one input and one output, then your system could probably be addressed mathematically by using Linear Programming or at worst Quadratic Programming (depending upon the model formulas). Though it would be fair to want to try GA with a FIS to compare efficiency and accuracy.
One thing I can say is that your method of constructing FIS is really slow. There must be a lot of overhead or something like that.
To reduce that, I would suggest that you construct a FIS before the ga portion, stopping just before the addrule call. It looks to me as if this is not a handle object that is created -- otherwise you would not need to assign the output of the addrule() overtop of a. So you should be able to construct up to that point, pass the partly-constructed FIS into the objective function, and then have each objective call addrule() the appropriate specific rules to what would then effectively be a local copy of the FIS.
Categories
Find more on Fuzzy Inference System Tuning in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!