I want to tune my fuzzy controller using GA

3 ビュー (過去 30 日間)
Armin Lotfy
Armin Lotfy 2022 年 5 月 11 日
回答済み: Pratyush Swain 2024 年 2 月 1 日
Hi guys,
I want to tune a fuzzy controller but it gives me the following error, anyone can help me?
cost_Fcn_ block:
function cost = flc_cost_fcn(p)
global flc1 flc
flc = flc1;
a = floor(p(1:9));
flc.Rules(1,1).Consequent(1) = a(1);
flc.Rules(1,1).Consequent(2) = a(2);
flc.Rules(1,1).Consequent(3) = a(3);
flc.Rules(1,2).Consequent(1) = a(4);
flc.Rules(1,2).Consequent(2) = a(5);
flc.Rules(1,2).Consequent(3) = a(6);
flc.Rules(1,4).Consequent(1) = a(4);
flc.Rules(1,4).Consequent(2) = a(5);
flc.Rules(1,4).Consequent(3) = a(6);
flc.Rules(1,3).Consequent(1) = a(7);
flc.Rules(1,3).Consequent(2) = a(8);
flc.Rules(1,3).Consequent(3) = a(9);
flc.Rules(1,5).Consequent(1) = a(7);
flc.Rules(1,5).Consequent(2) = a(8);
flc.Rules(1,5).Consequent(3) = a(9);
flc.Rules(1,7).Consequent(1) = a(7);
flc.Rules(1,7).Consequent(2) = a(8);
flc.Rules(1,7).Consequent(3) = a(9);
flc.Rules(1,6).Consequent(1) = 3-a(4);
flc.Rules(1,6).Consequent(2) = 3-a(5);
flc.Rules(1,6).Consequent(3) = 3-a(6);
flc.Rules(1,8).Consequent(1) = 3-a(4);
flc.Rules(1,8).Consequent(2) = 3-a(5);
flc.Rules(1,8).Consequent(3) = 3-a(6);
flc.Rules(1,9).Consequent(1) = 3-a(1);
flc.Rules(1,9).Consequent(2) = 3-a(2);
flc.Rules(1,9).Consequent(3) = 3-a(3);
flc.input(1).mf(1).params(3) = p(10);
flc.input(1).mf(2).params(2) = p(10);
flc.input(1).mf(3).params(1) = p(10);
flc.input(2).mf(1).params(3) = p(11);
flc.input(2).mf(2).params(2) = p(11);
flc.input(2).mf(3).params(1) = p(11);
flc.output(1).mf(1).params(3) = p(12);
flc.output(1).mf(2).params(2) = p(12);
flc.output(1).mf(3).params(1) = p(12);
flc.output(2).mf(1).params(3) = p(13);
flc.output(2).mf(2).params(2) = p(13);
flc.output(2).mf(3).params(1) = p(13);
flc.output(3).mf(1).params(3) = p(14);
flc.output(3).mf(2).params(2) = p(14);
flc.output(3).mf(3).params(1) = p(14);
% update gain
% k1 = p(15);
% k2 = p(16);
% k3 = p(17);
k1=1;
k2=1;
k3=1;
sim('VTS_challenge_2021','SrcWorkspace','Current');
cost = sum((v_veh_fuzzy - v_veh_ref_fuzzy)^2);
GA_block:
clc
warning('off')
k1=1;
k2=1;
k3=1;
global flc1 flc
flc1 = fis;
%LB & UB================================================
LB = [ 1 1 1 1 1 1 1 1 1 0 -5.1 0.01 0.01 0.01 ];
UB = [ 3 3 3 3 3 3 3 3 3 100 4 1 1 1 ];
%=======================================================
nvar = 14;
%=======================================================
FitnessF = @(x) flc_cost_fcn(x);
%=======================================================
opt = optimoptions('ga', 'Display','iter',...
'MaxGenerations', 200*nvar, ...
'PopulationSize', 100, ...
'FunctionTolerance', 1e-6, ...
'PlotFcn' , @gaplotbestf );
[x, fval] = ga(FitnessF,nvar,[],[],[],[],LB,UB,[],opt);
[cost, out] = flc_cost_fcn(x);
ERROR:
Error using fismf/set.params (line 229)
First parameter must be less than or equal to second parameter.
Error in flc_cost_fcn (line 50)
flc.input(1).mf(2).params(2) = p(10);
Error in untitled5>@(x)flc_cost_fcn(x) (line 17)
FitnessF = @(x) flc_cost_fcn(x);
Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11)
fcn_handle = @(x) fcn(x,FcnArgs{:});
Error in makeState (line 58)
firstMemberScore = FitnessFcn(state.Population(initScoreProvided+1,:));
Error in galincon (line 24)
state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ga (line 414)
[x,fval,exitFlag,output,population,scores] = galincon(FitnessFcn,nvars, ...
Error in untitled5 (line 25)
[x, fval] = ga(FitnessF,nvar,[],[],[],[],LB,UB,[],opt);
Caused by:
Failure in initial user-supplied fitness function evaluation. GA cannot continue.
  1 件のコメント
Sam Chak
Sam Chak 2022 年 5 月 19 日
編集済み: Sam Chak 2022 年 5 月 19 日
Can you put comments on each line?
This helps people to understand what your code does.
Can you "sketch" mathematically how your fuzzy controller looks like?

サインインしてコメントする。

回答 (1 件)

Pratyush Swain
Pratyush Swain 2024 年 2 月 1 日
Hi Armin,
The error stack you've provided is a sequence of function calls that led to the error of the fuzzy controller. Now let's analyse the main error message.
1- Error using fismf/set.params (line 229)
First parameter must be less than or equal to second parameter.
This error is thrown by the "set.params" method, which is trying to enforce a rule that the parameters of a membership function must be in ascending order.
2- Error in flc_cost_fcn (line 50)
flc.input(1).mf(2).params(2) = p(10);
The code attempts to assign a new value to the second parameter of the second membership function for the first input " flc.input(1).mf(2).params(2) ". The assigned value "p(10)" violates required condition for the parameters of the membership function. The value of "flc.input(1).mf(2).params(2)" must be equal to or greater than "flc.input(1).mf(2).params(2)".
To fix this error, you would need to ensure that any assignments to the parameters respect the required ordering. This could involve checking the values of the parameters before assignment and potentially modifying the bounds or constraints within the genetic algorithm to prevent such violations.
For more information on tuning fuzzy controller systems, please refer to https://www.mathworks.com/help/fuzzy/tune-fuzzy-inference-systems.html
Hope this helps.

カテゴリ

Help Center および File ExchangeFuzzy Logic Toolbox についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by