Fuzzy sets were first proposed by Lofti A. Zadeh in his 1965 paper entitled none other than: Fuzzy Sets. This paper laid the foundation for all fuzzy logic that followed by mathematically defining fuzzy sets and their properties. The definition of a fuzzy set then, from Zadeh's paper is:
This definition of a fuzzy set is like a superset of the definition of a set in the ordinary sense of the term. The grades of membership of 0 and 1 correspond to the two possibilities of truth and false in an ordinary set. The ordinary Boolean operators that are used to combine sets will no longer apply; we know that 1 AND 1 is 1, but what is 0.7 AND 0.3? This will be covered in the fuzzy operations section.
Membership functions for fuzzy sets can be defined in any number of ways as long as they follow the rules of the definition of a fuzzy set. The Shape of the membership function used defines the fuzzy set and so the decision on which type to use is dependant on the purpose. The membership function choice is the subjective aspect of fuzzy logic, it allows the desired values to be interpreted appropriately. The most common membership functions are shown below: Figure 4
Figure 4: most common membership functions
2-4 DEFINING FUZZY OPERATIONS
Traditional Bivalent logic uses the boolean operators AND, OR, and NOT to perform the intersect, union and complement operations. These operators work well for bivalent sets and can be essentially defined using the following truth table:
The truth table above works fine for bivalent logic but fuzzy logic does not have a finite set of possibilities for each input; this makes for an infinitely large truth table. The operators need to be defined as functions for all possible fuzzy values, that is, all real numbers from 0 to 1 inclusive. Fuzzy logic is actually a superset of bivalent logic since it includes the bivalent options (0,1) as well as all reals in between, so a generalized form of these operators will be usefull. The generalized form for these three operators are:
Using these definitions they can be applied to all of the bivalent combinations above as well as some fuzzy number combinations. The truth table for this can be seen below:
2-5 MAKING FUZZY DECISIONS
Most decisions that people make are logical decisions, they look at the situation and make a decision based on the situation. The generalized form of such a decision is called a generalized modus ponens, which is in the form:
If P, then Q.
P.
Therefore, Q.
This form of logical reasoning is fairly strict, Q can only be if P. Fuzzy logic loosens this strictness by saying that Q can mostly be if P is mostly or:
If P, then Q.
mostly P.
Therefore, mostly Q.
Where P and Q are now fuzzy numbers. The reasoning above requires a set of rules to be defined. These rules are linguistic rules to relate different fuzzy sets and numbers. The general form of these rules are: "if x is A then y is B," where x and y are fuzzy numbers in the fuzzy sets A and B respectivly. These fuzzy sets are defined by membership functions. There can be any number of input and output membership functions for the same input as well, depending on the number of rules in the system. For example, a system could have membership functions that represent slow, medium, and fast as inputs.
The linguistic rules are used to define the relation between the input and the output, but how exactly are the output fuzzy values determined? There are several ways to determine the answer based on the inputs, mainly the Mamdani, Larsen, Takagi-Sugeno-Kang, and Tsukamoto inference and aggregation methods. Firstly, we must describe the basic general set of rules, they will bet a set of rules that have one input in a fuzzy set and one output in a fuzzy set:
If x is Ai then y is Bi, i=1,2,...n
Let us look at a system that has two input membership functions (A1,A2) and two output membership functions (B1, B2). These membership functions, shown below in Figure 5, define the fuzzy sets A and B in the above general inference rule.
Figure 5: fuzzy sets A and B in the above general inference rule
A1 and A2 are shown on the left, with A1 in blue and A2 in green. On the right B1 is blue and B2 is green. We will be using the Mamdani inference model to combine the sets and rules. The Mamdani inference model is:
R(x,y) = pg110 in Nguyen
Using this model will give an aggregate fuzzy set, R, that uses the input values in A1 and A2 to modify and combine B1 and B2. The input membership functions, as well as the output membership functions, are overlapping; this means that an input value can have membership in both membership functions, or in only one. If the input value has membership in a function, than any rule using that membership funciton is said to 'fire' and produce a result. These results are then aggregated using the Mamdani model, or a different model.
Let us then pick and input value that has membership function in A1 and A2, 1.25, this will cause both rules to fire. The value 1.25 has a membership of 0.75 in A1 and a membership of 0.25 in A2. Using the Mamdani model and these inputs the resulting aggregate output will be:
[A1(1.25) /\ B1(y)] \/ [A2(1.25) /\ B2(y)]
When all of these combinations have been made, the aggregate output membership function (red), as well as B1 and B2 (dashed) are shown below: Figure 6
Figure 6: the aggregate output membership function
This aggregate fuzzy membership function is the result of the rule based inference decision making process. To get a finite number as an output we need to go through the defuzzification process. Defuzzification is a method that produces a number that best represents, and consistenly represents the fuzzy set. There are many ways to do this with most of them being some type of averaging method. The most common is the centroid method, this calculates the center of area of the fuzzy set and uses the value at which this occurs as the defuzzified output. Other methods include the bisector, largest of maximum, smallest of maximum, and middle of maximum. For the above aggregate fuzzy set, the different defuzzification methods produce these finite values shown below. So, if the most common method, centroid, is used, the finite result would be 7.319.
2-6 FUZZY CONTROL
There is more to fuzzy logic than some interesting math, it has some impressive applications in engineering. The main application of fuzzy logic in engineering is in the area of control systems. The definition of a control system, given by Richard Dorf in Modern Control Systems is: "An interconnection of components forming a system configuration that will provide a desired response." This means that a control system needs to know the desired response (input) and it needs to process this input and attempt to achieve it. The general control system can then be summarized with the following diagram: Figure 7
Figure 7: The general control system
The process is the system that is being controlled and cannot typically be changed. The controller then, must take the input and also take measurements from the process and use this information to generate the appropriate input to the process. A basic example of a controller would be a summing point that will provide the difference between input and output to the process, whereas a more advanced controller would be a PID controller. A fuzzy logic based controller will use fuzzy membership functions and inference rules to determine the appropriate process input. Designing a fuzzy controller is a more intuitive approach to controller design since it uses a comprehendible linguistic rule base.
A fuzzy controller can be broken down into three main processes. The first of these is the fuzzification, this uses defined membership functions to process the inputs and to fuzzify them. These fuzzified inputs are then used in the second part, the rule-based inference system. This system uses previously defined linguistic rules to generate a fuzzy response. The fuzzy response is then defuzzified in the final process: defuzzification. This process will provide a real number as an output.
Designing a fuzzy controller can be done with several different computer based tools, the tool we will be using is the Fuzzy Logic Toolbox in MATLAB with Simulink. This toolbox provides a GUI for defining membership functions and inference rules and can be integrated with Simulink. The tutorials below will walk you through the process of designing a fuzzy controller using the Fuzzy Logic Toolbox. These tutorials assume that you are familiar with MATLAB and Simulink.
Chapter-3
Matlab Fuzzy Logic toolbox
3-1 INTRODUCTION
You can create and edit fuzzy inference systems with Fuzzy Logic Toolbox software. You can create these systems using graphical tools or command-line functions, or you can generate them automatically using either clustering or adaptive neuro-fuzzy techniques.
If you have access to Simulink software, you can easily test your fuzzy system in a block diagram simulation environment.
The toolbox also lets you run your own stand-alone C programs directly. This is made possible by a stand-alone Fuzzy Inference Engine that reads the fuzzy systems saved from a MATLAB session. You can customize the stand-alone engine to build fuzzy inference into your own code. All provided code is ANSI compliant.
Because of the integrated nature of the MATLAB environment, you can create your own tools to customize the toolbox or harness it with another toolbox, such as the Control System Toolbox™, Neural Network Toolbox™, or Optimization Toolbox™ software.
3-2 ANFIS Graphical User Interface
A- Fuzzy Inference System (FIS) Editor
B- Membership Function Editor
Chapter – 4
4-How to Run the Project
There is the explanation of the project and the information of the project how to be runned. In the next pages we showed some screenshots of our project.
As we see there are several files in our project. These are for needed configuration files and coding parts of the project and also it contains figure page which is our design.
We just double click the guiproje.m and we assume if you installed Matlab, there will be seen the code page. And then we push the start button for our project.
In our project, we made all of the linguistics of single and combine parts. It correctly draws the graph chosen. Just write to the “Enter the linguistic part “side your demands. For example bottom of the picture shows single linguistic was chosen and taken its graph. We just write there “not young” and then we push the “push the button” button and see our graph.
If we want combine linguistic again the same steps will be applied. For example “extremely young and extremely old” is written to the top of the box then we get the result correctly.
Important warning : You can also choose the options you want to make it’s graph from the scrolling bar. Just hit the linguistics and then see the results.
Here are some screenshots of our project:
Here are the main codes we wrote for this project and important parts will be explained.
Code of main part :
function varargout = guiproje(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @guiproje_OpeningFcn, ...
'gui_OutputFcn', @guiproje_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% --- Executes just before guiproje is made visible.
function guiproje_OpeningFcn(hObject, eventdata, handles, varargin)
x = (0:100)';
young = gbell_mf(x, [20, 2, 0]);
old = gbell_mf(x, [30, 3, 100]);
too_young = CON_mf(young);
too_old = CON_mf(old);
more_or_less_old = DIL_mf(old);
more_or_less_young = DIL_mf(young);
not_young_and_not_old = min(NEG_mf(young), NEG_mf(old));
not_young_or_not_old = max(NEG_mf(young), NEG_mf(old));
young_and_old = min(young,old);
young_or_old = max(young,old);
not_young = NEG_mf(young);
not_old = NEG_mf(old);
young_but_not_too_young = min(young, NEG_mf(CON_mf(young)));
old_but_not_too_old = min(old, NEG_mf(CON_mf(old)));
extremely_old = CON_mf(CON_mf(CON_mf(old)));
not_extremely_old = NEG_mf(extremely_old);
extremely_young = CON_mf(CON_mf(CON_mf(young)));
not_extremely_young = NEG_mf(extremely_young);
extremely_young_and_extremely_old = min(extremely_young,extremely_old);
extremely_young_or_extremely_old = max(extremely_young,extremely_old);
all = [more_or_less_old not_young_and_not_old ...
young_but_not_too_young extremely_old];
setappdata(handles.axes1,'x',x);
setappdata(handles.axes1,'young',young);
setappdata(handles.axes1,'old',old);
setappdata(handles.axes1,'too_young',too_young);
setappdata(handles.axes1,'too_old',too_old);
setappdata(handles.axes1,'more_or_less_old',more_or_less_old);
setappdata(handles.axes1,'more_or_less_young',more_or_less_young);
setappdata(handles.axes1,'not_young',not_young);
setappdata(handles.axes1,'not_old',not_old);
setappdata(handles.axes1,'not_young_and_not_old',not_young_and_not_old);
setappdata(handles.axes1,'not_young_or_not_old',not_young_or_not_old);
setappdata(handles.axes1,'young_and_old',young_and_old);
setappdata(handles.axes1,'young_or_old',young_or_old);
setappdata(handles.axes1,'young_but_not_too_young',young_but_not_too_young);
setappdata(handles.axes1,'old_but_not_too_old',old_but_not_too_old);
setappdata(handles.axes1,'extremely_old',extremely_old);
setappdata(handles.axes1,'not_extremely_old',not_extremely_old);
setappdata(handles.axes1,'extremely_young',extremely_young);
setappdata(handles.axes1,'not_extremely_young',not_extremely_young);
setappdata(handles.axes1,'extremely_young_and_extremely_old',extremely_young_and_extremely_old);
setappdata(handles.axes1,'extremely_young_or_extremely_old',extremely_young_or_extremely_old);
setappdata(handles.axes1,'all',all);
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes guiproje wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = guiproje_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
switch_variable = get(handles.edit1,'String');
if strcmp(switch_variable,'old')
disp('old');
gca = handles.axes1;
plot(getappdata(handles.axes1,'x'),getappdata(handles.axes1,'old'));
end
if strcmp(switch_variable,'young')
disp('young');
gca = handles.axes1;
plot(getappdata(handles.axes1,'x'),getappdata(handles.axes1,'young'));
end
if strcmp(switch_variable,'too old')
disp('too old');
gca = handles.axes1;
plot(getappdata(handles.axes1,'x'),getappdata(handles.axes1,'too_old'));
end
if strcmp(switch_variable,'too young')
disp('too young');
gca = handles.axes1;
plot(getappdata(handles.axes1,'x'),getappdata(handles.axes1,'too_young'));
end
if strcmp(switch_variable,'more or less old')
disp('more or less old');
gca = handles.axes1;
plot(getappdata(handles.axes1,'x'),getappdata(handles.axes1,'more_or_less_old'));
end
if strcmp(switch_variable,'more or less young')
disp('more or less young');
gca = handles.axes1;
plot(getappdata(handles.axes1,'x'),getappdata(handles.axes1,'more_or_less_young'));
end
if strcmp(switch_variable,'not young')
disp('not young');
gca = handles.axes1;
plot(getappdata(handles.axes1,'x'),getappdata(handles.axes1,'not_young'));
end
if strcmp(switch_variable,'not old')
disp('not old');
gca = handles.axes1;
plot(getappdata(handles.axes1,'x'),getappdata(handles.axes1,'not_old'));
end
if strcmp(switch_variable,'not young and not old')
disp('not young and not old');
gca = handles.axes1;
plot(getappdata(handles.axes1,'x'),getappdata(handles.axes1,'not_young_and_not_old'));
end
if strcmp(switch_variable,'not young or not old')
disp('not young or not old');
gca = handles.axes1;
plot(getappdata(handles.axes1,'x'),getappdata(handles.axes1,'not_young_or_not_old'));
end
if strcmp(switch_variable,'young and old')
disp('young and old');
gca = handles.axes1;
plot(getappdata(handles.axes1,'x'),getappdata(handles.axes1,'young_and_old'));
end
if strcmp(switch_variable,'young or old')
disp('young or old');
gca = handles.axes1;
plot(getappdata(handles.axes1,'x'),getappdata(handles.axes1,'young_or_old'));
end
if strcmp(switch_variable,'young but not too young')
disp('young but not too young');
gca = handles.axes1;
plot(getappdata(handles.axes1,'x'),getappdata(handles.axes1,'young_but_not_too_young'));
end
if strcmp(switch_variable,'old but not too old')
disp('old but not too old');
gca = handles.axes1;
plot(getappdata(handles.axes1,'x'),getappdata(handles.axes1,'old_but_not_too_old'));
end
if strcmp(switch_variable,'extremely old')
disp('extremely old');
gca = handles.axes1;
plot(getappdata(handles.axes1,'x'),getappdata(handles.axes1,'extremely_old'));
end
if strcmp(switch_variable,'extremely young')
disp('extremely young');
gca = handles.axes1;
plot(getappdata(handles.axes1,'x'),getappdata(handles.axes1,'extremely_young'));
end
if strcmp(switch_variable,'not extremely young')
disp('not extremely young');
gca = handles.axes1;
plot(getappdata(handles.axes1,'x'),getappdata(handles.axes1,'not_extremely_young'));
end
if strcmp(switch_variable,'not extremely old')
disp('not extremely old');
gca = handles.axes1;
plot(getappdata(handles.axes1,'x'),getappdata(handles.axes1,'not_extremely_old'));
end
if strcmp(switch_variable,'extremely young and extremely old')
disp('extremely young and extremely old');
gca = handles.axes1;
plot(getappdata(handles.axes1,'x'),getappdata(handles.axes1,'extremely_young_and_extremely_old'));
end
if strcmp(switch_variable,'extremely young or extremely old')
disp('extremely young or extremely old');
gca = handles.axes1;
plot(getappdata(handles.axes1,'x'),getappdata(handles.axes1,'extremely_young_or_extremely_old'));
end
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in listbox1.
function listbox1_Callback(hObject, eventdata, handles)
% hObject handle to listbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns listbox1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from listbox1
a = get(hObject,'Value');
gos = get(hObject,'String');
set(handles.edit1,'string',gos(a));
pushbutton1_Callback(hObject, eventdata, handles);
% --- Executes during object creation, after setting all properties.
function listbox2_Callback(hObject, eventdata, handles)
% hObject handle to listbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
a = get(hObject,'Value');
gos = get(hObject,'String');
set(handles.edit1,'string',gos(a));
pushbutton1_Callback(hObject, eventdata, handles);
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes during object creation, after setting all properties.
function figure1_CreateFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% --- Executes on selection change in listbox2.
function listbox2_Callback(hObject, eventdata, handles)
% hObject handle to listbox2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns listbox2 contents as cell array
% contents{get(hObject,'Value')} returns selected item from listbox2
% --- Executes during object creation, after setting all properties.
function listbox2_CreateFcn(hObject, eventdata, handles)
% hObject handle to listbox2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
ALADİN EKLENTİLERİNİ BURAYA YAP. ÖNEMLİ FONKSİYON AÇIKLAMALARIN VARSA VE PROJEYİ YAPARKEN NEYE DİKKAT ETTİK FİLAN DİYE BU KISMA YAZ.
BİRDE SANA GÖNDERDİĞİM PROJENİN İÇERİSİNDEN O MİDDLE AGED İ DÜZELT ABİCİM TAMAMDIR. GERİ YOLLA BANA ÇIKTI ALACAM..
Linguistic Variables
A numerical variables takes numerical values:
Age = 65
A linguistic variables takes linguistic values:
Age is old
A linguistic values is a fuzzy set.
All linguistic values form a term set:
T(age) = {young, not young, very young, ...
middle aged, not middle aged, ...
old, not old, very old, more or less old, ...
not very yound and not very old, ...}
- The syntactic rule refers to the way the terms in T(age) are generated
- The semantic rule defines the membership function of each linguistic value of the term set
- The term set consists of primary terms as (young, middle aged, old) modified by the negation (“not”) and/or the hedges (very, more or less, quite, extremely,…) and linked by connectives such as (and, or, either, neither,…)
Operations on Linguistic Values
Bizim fonksiyonlarimiz
-
A2 = CON(A) is called the concentration operation
-
√A = DIL(A) is called the dilation operation
- CON(A) & DIL(A) are useful in expression the hedges such as “very” & “more or less” in the linguistic term A
- Other definitions for linguistic hedges are also possible
References
1-Zwart, A., Smith, N., and E. Beneken (1972), Multiple model approach to uptake and distribution of halothane: The use of an analogue computer, Computers and Biomedical research, 5, 228-238.
2-Derighetti, M. (1999). Feedback control in anaesthesia, PhD thesis, Swiss Federal Institute of Technology, Zurich. Lawson, C.L. and R.J. Hanson (1974). Solving Least-Squares Problems, Prentice Hall Series in Automatic Computation, Englewood Cliffs, New Jersey, USA.
3-Mahfouf, M. and D.A. Linkens (1998), Generalised Predictive Control and Bioengineering, Taylor and Francis, London,
ISBN 0-7484-0597-6.