# Fuzzy logic rule for out of range

조회 수: 10(최근 30일)
Luca Ferro 2023년 2월 9일
댓글: Luca Ferro 2023년 3월 22일
I implemented a fuzzy logic penalty system for a particle swarm algorithm i'm working on.
Sometimes it may happen that the values considered are out of the range defined in the fuzzy logic [0 1], so i get this warning:
Warning: Input 1 expects a value in range [0 1], but has a value of 1.06985.
and by default the defuzzifier does this:
Warning: No rules fired for Output 1. Defuzzified output value set to its mean range value 0.05.
Is there a way to set a rule for the out of range values so that its default output is an arbitrary value decided by me and not the mean?
Basically i would like to keep both warnings, and have the second one like this:
Warning: No rules fired for Output 1. Defuzzified output value set to MY ARBITRARY VALUE LET'S SAY 2.
Note: i know i could just expand the fuzzy range to fit, but it would be a blind guess since i don't actually know the upper bound. If nothing works i'll do it like this (expanding to let's say to [0 1.5], so a 50% margin).
Note2: i cannot attach the fuzzy logic beacuse .fis files upload is not supported, i'll just copy paste it in the comments:
##### 댓글 수: 1표시 없음숨기기 없음
Luca Ferro 2023년 2월 9일
this is the fuzzy logic file:
[System]
Name='risetimeFuzzy'
Type='mamdani'
Version=2.0
NumInputs=1
NumOutputs=1
NumRules=5
AndMethod='min'
OrMethod='max'
ImpMethod='min'
AggMethod='max'
DefuzzMethod='centroid'
[Input1]
Name='rtRatio'
Range=[0 1]
NumMFs=5
MF1='eF':'trimf',[0 0 0.08]
MF2='jR':'trimf',[0.15 0.35 0.6]
MF3='eS':'trimf',[0.75 1 1]
MF4='qF':'trimf',[0.002 0.08 0.25]
MF5='qS':'trimf',[0.45 0.7 1]
[Output1]
Name='output1'
Range=[0 0.1]
NumMFs=3
MF1='lnP':'trimf',[0 0 0.015]
MF2='hP':'trimf',[0.03 0.06 0.1]
MF3='lmP':'trimf',[0.01 0.02 0.04]
[Rules]
1, 2 (1) : 1
4, 3 (1) : 1
2, 1 (1) : 1
5, 3 (1) : 1
3, 2 (1) : 1

댓글을 달려면 로그인하십시오.

### 채택된 답변

Kartik 2023년 3월 21일
Hi,
Yes, you can define a default output value for out-of-range inputs in your fuzzy logic system. One way to do this is by adding a new membership function to the input variable that covers the out-of-range region and assigns a fixed output value.
Here's an example of how you could modify your 'rtRatio' input variable to handle out-of-range values:
[Input1]
Name='rtRatio'
Range=[0 1]
NumMFs=6
MF1='eF':'trimf',[0 0 0.08]
MF2='jR':'trimf',[0.15 0.35 0.6]
MF3='eS':'trimf',[0.75 1 1]
MF4='qF':'trimf',[0.002 0.08 0.25]
MF5='qS':'trimf',[0.45 0.7 1]
MF6='outofrange':'trapmf', [1.01 1.05 1.1 1.2], 2
In this example, a new membership function called 'outofrange' has been added to the 'rtRatio' input variable. This membership function is a trapezoidal function that covers the out-of-range region from 1.01 to 1.2 and assigns a fixed output value of 2.
With this modification, if an input value falls within the 'outofrange' membership function, the output value for that input will be fixed at 2, regardless of the fuzzy logic rules.
Note that you can adjust the range and shape of the 'outofrange' membership function to fit your specific needs.
##### 댓글 수: 3표시 이전 댓글 수: 2숨기기 이전 댓글 수: 2
Luca Ferro 2023년 3월 22일
Maybe i'm misunderstanding the code but wouldn't this solution
MF6='outofrange':'trapmf', [1.01 1.05 1.1 1.2], 2
still have a upper bound that can be traspassed? like what would happen if the input is 1.5 (so major than 1.2 of the trapezoid)?
The shape i would like to have is open on the right side.

댓글을 달려면 로그인하십시오.

### 추가 답변(1개)

Sam Chak 2023년 3월 22일
Thanks for the sketch. I don't know your desired intervals, but linsmf should be the one that looks like your sketch.
MF6='outofrange':'linsmf', [param(1) param(2)], 2
The function looks like this:
x = 0.5:0.01:3;
y = linsmf(x, [1.0 1.5]);
plot(x, y, 'linewidth', 1.5), grid on
title('Linear Saturation function')
xlabel('linsmf, P = [1.0 1.5]')
ylabel('Membership')
ylim([-0.05 1.05])
##### 댓글 수: 1표시 없음숨기기 없음
Luca Ferro 2023년 3월 22일
yep that's it. I'll try and update you as soon as possible

댓글을 달려면 로그인하십시오.

### 범주

Find more on Data Clustering in Help Center and File Exchange

R2022a

### Community Treasure Hunt

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

Start Hunting!

Translated by