fuzzy tuning error using a custom cost function
2 ビュー (過去 30 日間)
古いコメントを表示
after runing this command to tune
fisRuleTuned = tunefis(FIS1,rule,fcn,options);
i am getting these errors
Error using costFcn
Unrecognized method, property, or field 'signals' for class
'Simulink.SimulationData.Dataset'.
Error in @(fis)costFcn(fis,model,minLevel,refLevel,wsVars,minData)
Error in fuzzy.tuning.internal.fisFitnessFcnWithoutIntCon>localFcn (line 54)
fitness = fitnessFcn(fis);
Error in fuzzy.tuning.internal.fisFitnessFcnWithoutIntCon (line 25)
fitness(i) = localFcn(params(i,:),fis,spec,fitnessFcn,discSet, ...
Error in fuzzy.tuning.internal.optimFISWithGA>@(x)fuzzy.tuning.internal.fisFitnessFcnWithoutIntCon(x,pdata.fis,pdata.spec,evalFcn,pdata.discset,options.IgnoreInvalidParameters,false,options.TuningOutputSinks) (line 70)
p.fitnessfcn = @(x)fuzzy.tuning.internal.fisFitnessFcnWithoutIntCon(...
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 420)
[x,fval,exitFlag,output,population,scores] = galincon(FitnessFcn,nvars, ...
Error in fuzzy.tuning.internal.optimFISWithGA (line 89)
[params,fval,exitflag,output,population,scores] = ga(p);
Error in tunefis (line 326)
[varargout{1:nargout}] = fuzzy.tuning.internal.optimFISWithGA(pdata,fitnessFcn,options,kFoldData);
Caused by:
Failure in initial user-supplied fitness function
evaluation. GA cannot continue.
the cost function i have used below
function cost = costFcn(fis,model,minLevel,refLevel,wsVarNames,varargin)
assignin('base',wsVarNames,fis)
out = sim(model);
glucose = out.yout.signals(1).values;
insulin = out.yout.signals(2).values;
tout = out.yout.time;
err = glucose - refLevel;
err(glucose<minLevel) = 100;
errSquare = err.^2;
meanSquare = mean(errSquare);
cost = sqrt(meanSquare);
if isempty(varargin)
return
end
data = varargin{1};
if cost < data.MinCost
data.MinCost = cost;
data.MinGlucose = glucose;
data.MinInsulin = insulin;
data.fisMin = fis;
data.Tout = tout;
end
end
1 件のコメント
Sam Chak
2023 年 4 月 24 日
Have you tried extracting the data from out.yout.signals, and then pass them to the CostFcn as trainingData?
function cost = costFcn(fis, model, minLevel, refLevel, wsVarNames, varargin)
assignin('base', wsVarNames, fis)
out = sim(model);
glucose = out.yout.signals(1).values;
insulin = out.yout.signals(2).values;
tout = out.yout.time;
err = glucose - refLevel;
err(glucose<minLevel) = 100;
errSquare = err.^2;
meanSquare = mean(errSquare);
cost = sqrt(meanSquare);
if isempty(varargin)
return
end
data = varargin{1};
if cost < data.MinCost
data.MinCost = cost;
data.MinGlucose = glucose;
data.MinInsulin = insulin;
data.fisMin = fis;
data.Tout = tout;
end
end
回答 (1 件)
Akshat Dalal
2023 年 8 月 31 日
Hello Naveen,
I understand you are facing some errors in using a custom cost function while tuning a fuzzy system using the Fuzzy Logic Toolbox.
I believe your custom cost function is inspired from the Fuzzy Logic Toolbox example provided in documentation - https://in.mathworks.com/help/releases/R2023a/fuzzy/design-fuzzy-logic-controller-for-artificial-pancreas.html
Assuming that is the case, I ran this example using your custom cost function and it did not produce any errors. I believe this error is occurring due to a discrepancy in your model. You could refer the example documentation for more information.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Fuzzy Logic Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!