Issues with minimizing function using genetic algorithm.

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.

2 Comments

You do not bound the values for x1...x6 with upper and lower bounds when calling ga. Maybe this causes an error when the function tries to calculate the fuzzy system, for example if some x values get less then zero.
I tried that but had the same errors.

Sign in to comment.

Answers (1)

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

I would appreciate it if you could explain further. I have only a membership function which I intend to optimize. How do I define inequalities for these membership functions?
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.
yes, I understand how to define it not in the way Walter described it. Which is why I asked for more clarification.
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?
For 3 variables, A would be
[1 -1 0
0 1 -1]
I get Stephens explanation I am just a bit lost as to how to define the inequality for it.
Walter please explain the matrix you posted .
please, how do I also go about defining the 'b' for the inequality?
A=[1 -1 0 0 0 0; 0 1 -1 0 0 0; 0 0 1 -1 0 0; 0 0 0 0 1 -1] b=[-eps;-eps;-eps;-eps]
for six variables is this correct?
After redfining the call function to include the inequalities the error i got is shown below;
M=[14000,15555,16000,17000,18000,19000;
14555,15555,16000,17555,18530,19000];
A = [1 -1 0 0 0 0;
0 1 -1 0 0 0;
0 0 1 -1 0 0;
0 0 0 0 1 -1];
b=[-eps;-eps;-eps;-eps] ;
options = gaoptimset('InitialPopulation',M);
[x fval] = ga(@FuzzyForecast,6,A,b,[],[],[],[],options)
Error using functionHandleOrCell (line 12)
The constraint function must be a function handle.
Error in validate (line 175)
[nonlcon,NonconFcnArgs] = functionHandleOrCell('NonconFcn',nonlcon);
Error in gacommon (line 72)
[options,nvars,FitnessFcn,NonconFcn] = validate(options,type,nvars,fun,nonlcon,user_options);
Error in ga (line 327)
[x,fval,exitFlag,output,population,scores,FitnessFcn,nvars,Aineq,bineq,Aeq,beq,lb,ub, ...
I understand the matrix now but I would know how to address the error message. I am told to the constraint should be a function handle. Do I have to define it as a function and pass it? the call function for the ga inequality accepts a matrix and a vector ( A and b respectively).
You put the options in the slot reserved for the nonlinear constraint. You need one more [] before options.
Just modified it still getting errors
Error using evalfismex
Illegal parameters in fisTriangleMf() --> b > c
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 galincon (line 17)
state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ga (line 359)
[x,fval,exitFlag,output,population,scores] = galincon(FitnessFcn,nvars, ...
Caused by:
Failure in user-supplied fitness function evaluation. GA cannot continue.
"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?
The problem is from me actually. I am trying to figure out how to correct it. I am implementing a fuzzy time series forecast using the genetic algorithm. The problem starts with the logical relationships I developed.
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.

Sign in to comment.

Categories

Asked:

on 22 Sep 2018

Commented:

on 23 Sep 2018

Community Treasure Hunt

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

Start Hunting!