Build Mamdani Systems (Code) - MATLAB & Simulink - MathWorks India

March 26, 2018 | Author: Arsheel Khan | Category: Matlab, C (Programming Language), Fuzzy Logic, Computer Engineering, Areas Of Computer Science


Comments



Description

Build Mamdani Systems (Code) On this page… Tipping Problem from the Command Line System Display Functions Building a System from Scratch FIS Evaluation The FIS Structure Tipping Problem from the Command Line The tipping problem is one of many Fuzzy Logic Toolbox™ examples of fuzzy inference systems. The FIS is alw ays cast as a MATLAB® structure. To load this system, type: a=r e a d f i s ( ' t i p p e r . f i s ' ) This command returns the follow ing result: a= n a m e :' t i p p e r ' t y p e :' m a m d a n i ' a n d M e t h o d :' m i n ' o r M e t h o d :' m a x ' d e f u z z M e t h o d :' c e n t r o i d ' i m p M e t h o d :' m i n ' a g g M e t h o d :' m a x ' i n p u t :[ 1 x 2s t r u c t ] o u t p u t :[ 1 x 1s t r u c t ] r u l e :[ 1 x 3s t r u c t ] The labels on the left of this listing represent the various components of the MATLAB structure associated w ith t i p p e r . f i s . To access the various components of this structure, type the component name after aat the MATLAB prompt. For example: a . t y p e returns the follow ing result: a n s= m a m d a n i The function g e t f i s ( a ) returns almost the same structure information that typing a , alone does: N a m e =t i p p e r T y p e =m a m d a n i N u m I n p u t s=2 I n L a b e l s = s e r v i c e f o o d N u m O u t p u t s=1 O u t L a b e l s= see Create a Structure Array and Create a Cell Array in the MATLAB documentation. 1 . ' i n p u t ' . but you can get it by typing g e t f i s ( a . 1 ) g e t f i s ( a . ' o u t p u t ' . you can obtain structure information using g e t f i sin this manner. m f e d i t ( a )displays the Membership Function Editor. For example. . you could type a=s e t f i s ( a . try s h o w f i s ( a ) This syntax returns a printout listing all the information about a . you cannot get information by typing a . ' n a m e ' . m f ( 1 ) The function g e t f i sis loosely modeled on the Handle Graphics ® function g e t . If you w ant a little more insight into this FIS structure. n a m e=' g r a t u i t y ' . type a . r u l e e d i t ( a )displays the Rule Editor. ' g r a t u i t y ' ) . you can display any of the GUIs for the tipping system directly from the command line. This function is intended more for debugging than anything else. For more information on the syntax for MATLAB structures and cell arrays. For example. Now the FIS structure ahas been changed to reflect the new name.t i p N u m R u l e s=3 A n d M e t h o d=m i n O r M e t h o d=m a x I m p M e t h o d=m i n A g g M e t h o d=m a x D e f u z z M e t h o d=c e n t r o i d Some of these fields are not part of the structure a . i n p u t ( 1 ) .designates the fuzzy tipping system. because ais already a MATLAB structure. but it show s all the information recorded in the FIS structure Because the variable. ' m f ' . r u l e v i e w ( a )displays the Rule View er. if you w anted to change the name of this system. Thus. The function s e t f i sacts as the reciprocal to g e t f i s . It allow s you to change any property of a FIS. I n l a b e l s . ' i n p u t ' . Any of the follow ing functions w ill display the tipping system w ith the associated GUI: f u z z y ( a )displays the FIS Editor. How ever. you can set this information more simply by typing a . g e t f i s ( a . f i e l dsyntax also generates this information. s u r f v i e w ( a )displays the Surface View er. 1 ) The s t r u c t u r e . a . ' I n l a b e l s ' ) Similarly. i n p u t or a . 1 ) g e t f i s ( a . p l o t m f . and g e n s u r f . then a n f i s e d i t ( a )displays the ANFIS Editor GUI. p l o t m f ( a . ais a Sugeno-type FIS. 1 ) returns the follow ing plots . When you open any of these GUIs. the function p l o t m f plots all the membership functions associated w ith a given variable as follow s. ' i n p u t ' . The first of these displays the w hole system as a block diagram much as it w ould appear on the FIS Editor. p l o t f i s ( a ) After closing any open MATLAB figures or GUI w indow s.If. in addition. you can access any of the other GUIs using the pull-dow n menu rather than the command line. System Display Functions There are three functions designed to give you a high-level view of your fuzzy inference system from the command line: p l o t f i s . if p l o t m fis called w hile either of these is open. ' o u t p u t ' . Finally. or in an open MATLAB figure. g e n s u r f ( a ) . the function g e n s u r fplots any one or tw o inputs versus any one output of a given system. The result is either a tw o-dimensional curve. g e n s u r fmust be generated w ith all but tw o inputs fixed. When there are three or more inputs.p l o t m f ( a . 1 ) These plots appear in the Membership Function Editor GUI. as is described in g e n s u r f . or a three-dimensional surface. a .a d d m f .a d d v a r . then the first m vector entries of the rule structure correspond to inputs 1 through m. For example. and so on. i n p u t ( 1 ) . n a m e = ' e x c e l l e n t ' . p a r a m s = [ 1 . m f ( 2 ) . The rules are built from statements such as the follow ing: If input1 is MF1 or input2 is MF3. m f ( 1 ) . m f ( 1 ) . p a r a m s = [ 1 .5) This rule is turned into a structure according to the follow ing logic. m f ( 2 ) . a . and a d d r u l e . The entry in column 2 is the index number for the membership function associated w ith input 2. 55 ] . has an index number. using the MATLAB structure syntax. a . a d d r u l eto do this. i n p u t ( 1 ) . or output. i n p u t ( 1 ) . a = n e w f i s ( ' t i p p e r ' ) . a . Use the command line function. Probably the most difficult part of this process is learning the shorthand that the fuzzy inference systems use for building rules. . i n p u t ( 1 ) . The structure associated w ith the preceding rule is 1320 . input. a . i n p u t ( 1 ) . r a n g e = [ 01 0 ] . m f ( 1 ) . The next n columns w ork the same w ay for the outputs.Building a System from Scratch You can build a fuzzy inference system using Fuzzy Logic Toolbox commands as an alternative to the GUI tools. you use the commands n e w f i s . i n p u t ( 1 ) . a . a . n a m e = ' g o o d ' . Column m + n + 1 is the w eight associated w ith that rule (typically 1) and column m + n + 2 specifies the connective used (w here AND = 1 and OR = 2). If there are m inputs to a system and n outputs. a . The entry in column 1 is the index number for the membership function associated w ith input 1. t y p e = ' g a u s s m f ' . 50 ] . t y p e = ' g a u s s m f ' . a . Each variable. n a m e = ' s e r v i c e ' . m f ( 3 ) . n a m e = ' p o o r ' . i n p u t ( 1 ) . and each membership function has an index number. 52 This sample code show s one w ay you can build the entire tipping system from the command line. i n p u t ( 1 ) . i n p u t ( 1 ) . to build the tipping system entirely from the command line. m f ( 2 ) . then output1 is MF2 (weight = 0. o u t p u t ( 1 ) . [ 1 . c o n n e c t i o n = 2 Tip You can also build the FIS structure using MATLAB w orkspace variables. n a m e = ' d e l i c i o u s ' . ' d e l i c i o u s ' . ' o u t p u t ' . r u l e ( 3 ) . These commands are in the m k t i p p e r . o u t p u t ( 1 ) . 1 . a = a d d m f ( a . a . a . n a m e = ' g e n e r o u s ' . ' t i p ' . r a n g e = [ 03 0 ] . i n p u t ( 2 ) . ' i n p u t ' . ' i n p u t ' . 1 . n a m e = ' f o o d ' . a . 2 . a . w e i g h t = 1 . p a r a m s = [ 2013 ] . ' g a u s s m f ' . o u t p u t ( 1 ) . i n p u t ( 1 ) . p a r a m s = [ 791 01 2 ] . ' g o o d ' . 51 0 ] ) . a . i n p u t ( 1 ) . r u l e ( 2 ) . ' g a u s s m f ' . ' i n p u t ' . r a n g e=r 1 . a . to specify the range of the input. a . a . 1 . ' t r i m f ' . o u t p u t ( 1 ) . a = a d d m f ( a . a = a d d v a r ( a . t y p e = ' t r a p m f ' . r a n g e = [ 01 0 ] . ' o u t p u t ' . Alternatively. ' o u t p u t ' . ' s e r v i c e ' . m f ( 2 ) . mfile. m f ( 2 ) . o u t p u t ( 1 ) . ' c h e a p ' . o u t p u t ( 1 ) . r u l e ( 1 ) . a . m f ( 3 ) . a . m f ( 2 ) . m f ( 3 ) . 50 ] ) . a . o u t p u t ( 1 ) . i n p u t ( 1 ) . a = a d d m f ( a . r u l e ( 2 ) . ' g a u s s m f ' . w e i g h t = 1 . i n p u t ( 2 ) . [ 01 0 ] ) . n a m e = ' r a n c i d ' . [ 1 01 52 0 ] ) . a . i n p u t ( 2 ) . a . ' i n p u t ' . a . m f ( 1 ) . [ 051 0 ] ) . m f ( 3 ) . ' g e n e r o u s ' . r u l e ( 2 ) . c o n s e q u e n t = [ 3 ] . you can build the entire tipping system from the command line using Fuzzy Logic Toolbox commands. ' t r i m f ' . ' a v e r a g e ' . m f ( 1 ) . o u t p u t ( 1 ) . m f ( 2 ) . [ 03 0 ] ) . m f ( 1 ) . r u l e L i s t = [. a . r u l e ( 1 ) . o u t p u t ( 1 ) . r u l e ( 3 ) . o u t p u t ( 1 ) . [ 2 02 53 0 ] ) . n a m e = ' c h e a p ' a . . a = a d d m f ( a . a . r u l e ( 1 ) . a . . a . 1 . i n p u t ( 2 ) . t y p e = ' t r i m f ' . c o n n e c t i o n = 2 . a = a d d m f ( a . ' i n p u t ' . ' t r a p m f ' . 55 ] ) . t y p e = ' g a u s s m f ' . c o n n e c t i o n = 1 . ' e x c e l l e n t ' . m f ( 3 ) . p a r a m s = [ 1 . m f ( 1 ) . a . a . p a r a m s = [ 2 02 53 0 ] . r u l e ( 2 ) . a n t e c e d e n t = [ 11 ] . a . ' p o o r ' . r u l e ( 3 ) . r u l e ( 3 ) . a n t e c e d e n t = [ 20 ] . a . a = n e w f i s ( ' t i p p e r ' ) . a = a d d v a r ( a . a = a d d m f ( a . a . a = a d d m f ( a . a n t e c e d e n t = [ 32 ] . ' t r i m f ' . a . 1 . ' i n p u t ' . a = a d d m f ( a .a . 51 0 ] . ' o u t p u t ' . o u t p u t ( 1 ) . . ' i n p u t ' . 1 . m f ( 1 ) . a . t y p e = ' t r i m f ' . i n p u t ( 2 ) . m f ( 2 ) . [ 1 . c o n s e q u e n t = [ 2 ] . For example. n a m e = ' t i p ' . a = a d d v a r ( a . t y p e = ' t r a p m f ' . i n p u t ( 2 ) . a . a . i n p u t ( 2 ) . a . p a r a m s = [ 1 01 52 0 ] . t y p e = ' t r i m f ' . [ 2013 ] ) . c o n s e q u e n t = [ 1 ] . r u l e ( 1 ) . i n p u t ( 2 ) . ' t r a p m f ' . [ 1 . m f ( 1 ) . a . w e i g h t = 1 . [ 01 0 ] ) . m f ( 3 ) . 2 . ' r a n c i d ' . a . m f ( 2 ) . p a r a m s = [ 051 0 ] . [ 791 01 2 ] ) . n a m e = ' a v e r a g e ' . a . type: r 1 =[ 01 0 ] a . ' f o o d ' . ' c u s t o m M F 1 ' . as show n in the follow ing example: a . e v a l f i s ( [ 35 . [1 2]. the follow ing script evaluates t i p p e rat the input. 1 . as show n in the follow ing example: a = a d d m f ( a . use the function e v a l f i s . 2 1 8 4 7 . To include a custom membership function. Specifying Custom Mem bership and Inference Functions You can create custom membership and inference functions as described in Specifying Custom Membership Functions. a = a d d r u l e ( a . This structure is stored inside each GUI tool. r u l e L i s t ) . d e f u z z M e t h o d = ' c u s t o m d e f u z z ' . FIS Evaluation To evaluate the output of a fuzzy system for a given input.a ) a n s= 5 .11112 20211 32312] . e v a l f i s ( [ 12 ] . To include a custom inference function. specify the name of the custom membership function. ' c u s t m f 1 ' . as show n in the follow ing diagram. because different input vectors are represented in different parts of the input structure. For example. This structure can itself be thought of as a hierarchy of structures. [ 01246891 0 ] ) . specify the name of the custom inference function. and specify them for building fuzzy inference systems at the command line. 5 5 8 6 This function can also be used for multiple collections of inputs. membership function definitions. All the information for a given fuzzy inference system is contained in the FIS structure. ' i n p u t ' . a=r e a d f i s ( ' t i p p e r ' ) . including variable names.a ) a n s= 1 2 . Access functions such as g e t f i sand s e t f i smake it easy to examine this structure. .27 ] . 7 8 8 5 The FIS Structure The FIS structure is the MATLAB object that contains all the fuzzy inference system information. and so on. and Specifying Custom Inference Functions. 3 1 . N u m R u l e s 7 . 3 6 . t i p p e r m a m d a n i [21] [32] 3 3 m i n m a x m i n m a x c e n t r o i d s e r v i c e f o o d t i p [01 0] [01 0] [03 0] p o o r g o o d e x c e l l e n t r a n c i d d e l i c i o u s c h e a p a v e r a g e g e n e r o u s g a u s s m f g a u s s m f g a u s s m f t r a p m f t r a p m f t r i m f t r i m f t r i m f [1 . 2 3 . 5000] [1 . 2 6 . as show n in the follow ing code sample: s h o w f i s ( a ) 1 . I m p M e t h o d 1 0 .A g g M e t h o d 1 1 . 3 0 . T y p e 3 . 2 5 . 2 2 . 2 1 . N u m I n p u t M F s 5 . 5500] [1 . 3 4 .I n M F T y p e s 2 7 .You can generate a listing of information on the FIS using the s h o w f i scommand. 3 3 . 2 8 . 1 7 . 2 9 .I n L a b e l s 1 3 . O r M e t h o d 9 .O u t R a n g e 1 8 .I n M F P a r a m s 3 5 .D e f u z z M e t h o d 1 2 . 2 0 .O u t M F T y p e s 3 2 . 51 000] . I n p u t s / O u t p u t s 4 .O u t L a b e l s 1 5 . A n d M e t h o d 8 .O u t M F L a b e l s 2 4 .I n M F L a b e l s 1 9 . 1 4 . N u m O u t p u t M F s 6 .I n R a n g e 1 6 . N a m e 2 . r m v a r . 55 ] M F 3 = ' e x c e l l e n t ' : ' g a u s s m f ' . 3 9 .a d d v a r . [ 791 01 0 ] . 4 4 . [ 1 . The follow ing sample show s the file t i p p e r .s h o w f i s . [ 0013 ] M F 2 = ' d e l i c i o u s ' : ' t r a p m f ' . 4 3 . 51 0 ] [ I n p u t 2 ] N a m e = ' f o o d ' R a n g e = [ 01 0 ] N u m M F s = 2 M F 1 = ' r a n c i d ' : ' t r a p m f ' . [ 1 . 4 4 . 4 3 . [ S y s t e m ] N a m e = ' t i p p e r ' T y p e = ' m a m d a n i ' N u m I n p u t s = 2 N u m O u t p u t s = 1 N u m R u l e s = 3 A n d M e t h o d = ' m i n ' O r M e t h o d = ' m a x ' I m p M e t h o d = ' m i n ' A g g M e t h o d = ' m a x ' D e f u z z M e t h o d = ' c e n t r o i d ' [ I n p u t 1 ] N a m e = ' s e r v i c e ' R a n g e = [ 01 0 ] N u m M F s = 3 M F 1 = ' p o o r ' : ' g a u s s m f ' . The rules appear in indexed format in a .R u l eC o n n e c t i o n 2 The list of command-line functions associated w ith FIS construction includes g e t f i s .a d d m f . 4 4 .O u t M F P a r a m s 4 0 . you also need to make certain that any rules requiring this membership function are also deleted.R u l eW e i g h t 4 3 . 4 4 . that changing one entry may oblige you to change another. If you prefer. You should be aw are. Saving FIS Files A specialized text file format is used for saving fuzzy inference systems. 4 2 .3 7 . 50 ] M F 2 = ' g o o d ' : ' g a u s s m f ' . how ever. 4 1 . f i stext file.R u l eA n t e c e d e n t [11] 4 2 . 3 8 . f i stext file rather than using any of the GUIs. 4 3 . you can modify the FIS by editing its . f i s . For example. [ 1 .s e t f i s . if you delete a membership function using this method. The functions r e a d f i sand w r i t e f i sare used for reading and w riting these files. [0013] [791 01 0] [051 00] [1 01 52 00] [2 02 53 00] [20] [32] 2 3 1 1 1 1 2 4 2 . and r m m f .a d d r u l e .R u l eC o n s e q u e n t 1 4 2 . [ O u t p u t 1 ] N a m e = ' t i p ' R a n g e = [ 03 0 ] N u m M F s = 3 M F 1 = ' c h e a p ' : ' t r i m f ' .1( 1 ):2 20 .3( 1 ):2 . [ 051 0 ] M F 2 = ' a v e r a g e ' : ' t r i m f ' . [ 2 02 53 0 ] [ R u l e s ] 11 . [ 1 01 52 0 ] M F 3 = ' g e n e r o u s ' : ' t r i m f ' .2( 1 ):1 32 .
Copyright © 2024 DOKUMEN.SITE Inc.