Aug 10, 2003 - applied to position-control of a motor-driven cart, and to identify and discuss issues ..... The simple GA (SGA) can be broken down into three distinct operations; ... The initial population will typically consist of 30â100 individual strings ...... for fitness-based update, reins.m, assumes a minimization problem. (ii).
John P. Byrne (50222465)
GA -Optimisation of a Fuzzy Logic Controller
Title:
GA-Optimisation of a Fuzzy Logic Controller M.Eng Project Report, School of Electronic Engineering, D.C.U.
Author:
John P. Byrne (Student ID: 50222465)
Date:
August 2003
Supervisor:
Ms. Jennifer Bruton School of Electronic Engineering, Dublin City University
Declaration I hereby declare that the work contained within this report, except where otherwise stated, is entirely my own and has not been previously submitted in whole, or in part, to any other educational institution.
Signed……………………………………………. Date……………………………………………….
M.Eng
1
DCU
John P. Byrne (50222465)
GA -Optimisation of a Fuzzy Logic Controller
Acknowledgements I would like to express my sincere gratitude to the following; My project supervisor, Ms.Jennifer Bruton (School of Electronic Engineering, Dublin City University) for her advice, guidance and support throughout the entire duration of this project. Dr Noel Gorman (Institute of Technlogy, Tallaght) for his help in relation to some of the mathematical aspects of Genetic Algorithms and decision theory. Mr Diarmuid Rush (Department of Mechanical Engineering, Institute of Technology, Tallaght) for insights into fuzzy controller design and the loan of numerous texts! Mr Traolach O’Brien (Department of Electronic Engineering, Institute of Technology, Tallaght) for his advice on conventional control theory. Dr. Joseph MacDonagh (Department of Humanities, Institute of Technology, Tallaght) for advice on dissertation-writing techniques and conventions My family; Joan, Sophie , Justin and Ciara, and my parents Michael and Kathleen, for their patience and support throughout.
M.Eng
2
DCU
John P. Byrne (50222465)
GA -Optimisation of a Fuzzy Logic Controller
Abstract The Knowledge Base of a Fuzzy Logic Controller (FLC) encapsulates expert knowledge and consists of the Data Base (membership functions) and Rule-Base of the controller. Optimization of both of these Knowledge Base components is critical to the performance of the controller and has traditionally been achieved through a process of trial and error. Such an approach is convenient for FLCs having low numbers of input variables (e.g. 2-3), however for greater numbers of inputs, more formal methods of Knowledge Base optimization are required. Genetic Algorithms (GAs) provide such a method. They are stochastic, but directed, numerical search methods which use operators consistent with evolutionary theory and find application in many disciplines, particularly function optimization problems. Although not learning algorithms in the strictest sense, GAs can be applied to learning tasks. In this study, the tripartite, Simple Genetic Algorithm (SGA) was evaluated as a feasible solution to the offline optimization/tuning of a simulated Fuzzy Logic Controller (FLC). The efficacy of this approach will be tested by comparison of the GA-FLC’s performance in controlling a positioncontrol system, to that of a conventional controller, as well as a heuristically-tuned, FLC.
M.Eng
3
DCU
John P. Byrne (50222465)
GA -Optimisation of a Fuzzy Logic Controller
Table of Contents 1 Introduction 7 1.1. Literature Review 8 1.2. Report Layout 12 2 Theory and Description of Genetic Algorithms. 13 2.1. What are Genetic Algorithms? 13 2.2. GA Parameters 14 2.3. Why GAs work – Schemata and the Schema Theorem 25 2.4. Comparison of GAs to Other Search Methods 30 3 Parametric Evaluation of the Simple Genetic Algorithm (SGA) 33 3.1. Introduction 33 3.2. GA Parameter Evaluation:- Optimised Function 33 3.3. Himmelblau Function 34 3.4. Evaluation Implementation 37 3.5. Parameter Initialisation, Representation and Decoding Issues 3.6. Evaluation (Matlab m-file implement2102.m) 41 3.7. Determination and Analysis of Optimal Parameter Set 42 3.8. Improving SGA Performance 57 3.9. Conclusions 59 4 Development and Simulation of a Conventional Position Controller 4.1. Introduction 62 4.2. Position Control System – Block Diagram 62 4.3. PID Control Model 68 4.4. System Block Diagram 69 4.5. Controller Design using Root Locus 71 4.6. PD Control 76 4.7. Simulink Model of the PD-Controlled Position System 77 5 Heuristic-Development and Simulation of a Fuzzy Position System80 5.1. Introduction 80 5.2. Fuzzy Logic Controller 80 5.3. Linguistic Variables, Rule Bases and Membership Functions 5.4. Fuzzy Logic Controller Architecture 82 5.5. Simulink Model of the Heuristic FLC 87 5.6. FLC Scaling Gains 88 6 Development and Evaluation of a GA -Optimised FLC Positio n System 6.1. Genetic Fuzzy Systems 91 6.2. GA-FLC using Matlab Fuzzy Inference System Definition 92 6.3. Decoding a GA -chromosome to yield a FIS 94 6.4. Decoding FLC Scaling Gains 101 6.5. Measure of FIS performance – GA Objective Function 101 6.6. Results 102 7 Summary and Conclusions 126 7.1. Summary 126 7.2. Conclusions 129
M.Eng
4
38
62
81
91
DCU
John P. Byrne (50222465)
GA -Optimisation of a Fuzzy Logic Controller
Table of Figures Figure 1: Single -point crossover 20 Figure 2: Multiple -point crossover (3-pt)21 Figure 3: Uniform crossover example 22 Figure 4: Schemata in binary strings 25 Figure 5: Numbers of schemata of particular lengths in a 3D domain space 28 Figure 6: The Himmelblau function 35 Figure 7: SGA parametric evaluation flowchart 37 Figure 8: S63 Optima Finds plot Figure 9: S43 Optima Finds plot 44 Figure 10: S63 Xoff performance 45 Figure 11 S43 Xoff performance 45 Figure 12: S63 Xon performance 46 Figure 13: S43 Xon performance 46 Figure 14: Standard deviation of fitness values for S43, S45 and S63 49 Figure 15: S43 search results for x1 and x2 for (a) 20k evaluations (b) 40k evaluations 51 Figure 16: Improving performance of large -population GAs 51 Figure 17: S43 higher population performance improvement 56 Figure 18: Restart strategy concept 58 Figure 19: Comparison of restart-GA to non-restart-GA 59 Figure 20: Motor-driven cart 62 Figure 21: Position system initial block diagram 62 Figure 22: System input potentiometer 63 Figure 23: Electro-mechanical model of the DC motor 64 Figure 24: Physical model of motor-wheel coupling 65 Figure 25: Rotor inertia and damping oppose the rotor rotation 66 Figure 26: Motor-cart transfer function 69 Figure 27: Uncompensated system block diagram 70 Figure 28: Uncompensated system root locus (a) unity gain (b) increased gain 72 Figure 29: Location of the compensator zero 73 Figure 30: Compensated system root locus (a) full view (b) zoomed 75 Figure 31: Compensated system step-response 75 Figure 32: Simulink model of the PD-control system 77 Figure 33: PD-control step responses (input of 10cm and 1cm with 20% disturbance) 78 Figure 34: Effect of reduction of input and feedback gains on system response 79 Figure 35: Fuzzy logic controller architecture 80 Figure 36: Degree of membership of ZERO and NS for input, e = 0.1 82 Figure 37: Inference mechanism operation 84 Figure 38: Heuristically-tuned FLC rule -base 85 Figure 39: Heuristic FLC rule -base firing for input [-0.1, 0.6] 86 Figure 40: Simulink model of system control using the he-FLC 87 Figure 41: Error ,e(t), and rate of change of error, de/dt corresponding to a step input of 0.01m Figure 42: Step-response of he-FLC system for input = 0.1m 90 Figure 43: Flowchart for the GA -optimisation attempt of a FLC 93 Figure 44: GA-chromosome structure used in the optimisation attempt 94 Figure 45: Fixed premise coordinate system, with premise spacing Ps = 1 96
M.Eng
5
DCU
89
John P. Byrne (50222465)
GA -Optimisation of a Fuzzy Logic Controller
Figure 46: Rule -base resulting from (CA = 67o , CS = 1 (Ps = 1), CO = PB-PS-Z-NS-NB) 96 Figure 47: Trapezoidal MF parameters 98 Figure 48: Using trapezoidal parameters to define triangular MFs 98 Figure 49: MF GA-chromosome segment (triangular MFs with non-uniform distribution) 100 Figure 50: MF GA-chromosome segment (trapezoidal MFs with uniform distribution) 100 Figure 51: Convergence data for GA 12Aug100512 104 Figure 52: Step responses of small population GA -FLCs 111 Figure 53: Step-responses of large-population GA -FLCs 112 Figure 54: Generation separation between restarts 114 Figure 55: Alleles lost for proportional fitness and ranked GAs 116 Figure 56: Step-response for ranked fitness GA with N=200 116 Figure 57: Optimised FLC yielded by the 2-phase, fixed-rule GA 118 Figure 58: Optimised FLC surface (2-phase fixed rule -size GA) 119 Figure 59: Optimised FLC yielded by 2-phase, variable rule base GA 125
M.Eng
6
DCU
John P. Byrne (50222465)
GA -Optimisation of a Fuzzy Logic Controller
1 Introduction Traditionally, control systems modeling has been based upon the use of mathematical techniques to model the input/output relationship of the system in question [1] [2]. Such an approach relies upon a mathematical description of the plant in order to model the behaviour of the system, subject to certain conditions and assumptions. Many real-world systems however, may not be as readily described mathematically due to the complexity of the components of the plant and the interaction between them, and consequently, the model may be subject to certain assumptions or conditions [3]. In such models, the degree of mathematical precision required to completely describe every aspect of the process, is either prohibitive or non-trivial. In addition, for actual implementation of such systems, heuristics, gained through human experience, are often employed in the tuning of the final controller [1][4]. The use of Fuzzy Logic [1][2] has found application in the area of control system design where human expert knowledge, rather than precise mathematical modeling, of a process or plant is used to model/implement the required controller [3] [4]. Human expert knowledge is based upon heuristic information gained in relation to the opration of the plant or process, and its inherent vagueness (“fuzziness”) offers a powerful tool for the modeling of complex systems. Uncertainty and ambiguity are evident in many engineering problems. For example, system stability can be considered fuzzy in the sense that a system can be lightly-damped, under-damped, over damped, etc. Fuzzy Logic Control (FLC) [1][2] therefore provides a formal method of translating subjective and imprecise human knowledge into control strategies, thus facilitating better system performance through the exploitation and application of that knowledge. Optimal design of the FLC Knowledge Base (membership functions and rule -base) is central to the performance of the FLC. The rule -base reflects the human expert knowledge, expressed as linguistic variables, while the membership functions represent expert interpretation of those same variables. In the absence of such knowledge, a common approach is to optimize these FLC parameters through a process of trial and error, with respect to the performance of the system for each Knowledge Base formulated [5]. This approach becomes impractical for systems having significant numbers of inputs since the rule-base size grows exponentially and consequently the number of rule combinations becomes significantly large [6]. Although a priori knowledge can eliminate the requirement to test
M.Eng
7
DCU
John P. Byrne (50222465)
GA -Optimisation of a Fuzzy Logic Controller
every possible combination, a more formal method is nonetheless required. The use of Genetic Algorithms (GA) in this regard can provide such a solution [7][8][9]. Genetic Algorithms (GAs) [10][11] are robust, numerical search methods that mimic the process of natural selection. Although not guaranteed to absolutely find the true global optima in a defined search space, GAs are renowned for finding relatively suitable solutions within acceptable time frames and for applicability to many problem domains [10]. Using primary concepts of genetic selection [10][11], crossover [10][11] and mutation [10][11], GAs are a stochastic, but directed method of identifying global optima within a problem domain-space. This is achieved through successive performance testing of potential solutions (i.e. members) which collectively form a population, with respect to a problem objective function. Information exchange between “betterperforming” candidates is facilitated by the genetic operators and occurs across generations of populations. In this way, convergence to optimal solutions is achieved. In this study, the tripartite, simple GA (selection, crossover and mutation only) was used to evaluate potential solutions for FLC rule -bases, with a view to optimizing the performance of the FLC, when applied to position-control of a motor-driven cart, and to identify and discuss issues arising from the evaluation.
1.1.
Literature Review
Conventional control system design is predominantly based upon the development of mathematical models, which attempt to describe the dynamic behaviour of the system in question using typically, differential equations. Many such methods of system design have been developed over time, including 3-term, Proportional, Integral, Derivative control (PID-control) [1][12], root-locus design [13], state-space [14] etc. offering a variety of ways in which good controller design may be achieved. In practice, PID (P, PI) control systems predominate, with approximately 90% of all controllers in operation, being of this form [1] [4]. The dominance of PID control may be explained by the fact that it is a long-standing, successful design technique, well understood by industrial users [7]. PID control however, has some disadvantages associated with it, one of which is that PID was originally designed for single -input, single -output (SISO) operation [3]. However, in practice, many real-world systems are multiple -input, multiple-output (MIMO), and control of such systems can be complicated involving several independent control loops [3]. For such systems, complex
M.Eng
8
DCU
John P. Byrne (50222465)
GA -Optimisation of a Fuzzy Logic Controller
mathematical models are required in order to exploit the interdependencies of physical variables and this may be impractical for several reasons, including lengthy model development time [4], and application of extensive simplifications or assumptions to the model, which at implementation stage will require heuristic tuning [3][4]. In addition, modelling the system is usually performed using the linear region of operation of the plant. This can lead to poor system response to disturbances or nonlinear behaviour, as a result of component wear and tear over time, for example. A second disadvantage associated with mathematical-based models is that heuristic information/knowledge which does not ‘fit easily’ into the mathematical framework of the model, tends not to be included in the design process, but rather is left to the tuning stage of model implementation thus rendering the model less robust [1]. Fuzzy Control [2] is the application of Fuzzy Logic [2] to control systems design. Fuzzy Logic was pioneered by Lotfi Zadeh [15] in 1965 and is a super-set of Boolean logic theory used to represent imprecision and uncertainty. Imprecision and uncertainty (i.e.”fuzziness”) are qualities inherent within human language when used to describe perceptions of observed events and objects. Uncertainty and imprecision, caused by non-linearities such as noise and disturbances, are also evident in the operation of real-world systems. The use of mathematical models to develop such systems may result in poor system performance if the dynamics of actual events do not form part of the model. This is because a full and complete mathematical model describing every possible causeand-effect event is not feasible [4]. The required degree of mathematical precision becomes even greater for non-linear system design. Increased mathematical complexity required for conventional modeling techniques thus led to the application of Fuzzy Logic to control systems design in the form of Fuzzy Logic Controllers1 and their use has steadily grown among industrial users [4]. The case for FLC is that it translates human abstractions/perceptions in the form of expert knowledge, into the numerical domain, thus facilitating suitable system controller design while avoiding the need for stringent mathematical, system descriptions [3]. Application of FLC in the domain of PID control has been, in general, used to augment existing PID controller operation or replacement of PID by FLC [3][16][17].
1
Ebrahim Mamdani was among the first to use fuzzy logic for system control in 1975 when he successfully used linguistic rules to control a model steam engine and boiler.
M.Eng
9
DCU
John P. Byrne (50222465)
GA -Optimisation of a Fuzzy Logic Controller
Increased technology sophistication, and use of microprocessors have enabled the development of Fuzzy-PID hybrid systems, where FLCs are used to adaptively tune the parameters of conventional PID controllers [16], and to PID controller replacement by FLCs [3] [17]. Visioli et al.[7] use FLCs to implement supervisory control by auto-tuning PID controller gains in order to adapt/optimize system performance (i.e. rise-time, overshoot and settling-time) of the controller in response to changing operating conditions. Fuzzy controllers have also been used in industrial and research applications where their use has conferred improved system performance, or where a mathematical process model is intractable. Examples of such applications are the 5MW, research nuclear reactor at the Massachusetts Institute of Technology (MIT) [3] and hydrogen leakage diagnosis systems used in the chemical industry [3]. The use of FLCs however requires optimized knowledge bases. Commonly, heuristic tuning of rule bases and/or membership functions has been through a combination of trial and error and expert knowledge [5]. For increasingly larger numbers of inputs and outputs (rule s), as well as membership functions, even with a priori, expert knowledge, this method becomes more difficult as the number of rules rises exponentially [6]. Artificial intelligence techniques such as Artificial Neural Networks (ANN) [2] and Genetic Algorithms have been advocated as solutions to this problem [2][9]. Neural Nets can be used to learn FLC rule-bases using input-output data, or to tune given membership functions. Such an approach combines the learning capability of the ANN with the reasoning power of fuzzy logic [2]. Alternatively, the search for suitable rules or membership function parameters of a FLC knowledge base can be viewed as an optimization problem to which a GA can be applied [9] [18]. Genetic Algorithms (GAs) are numerical optim ization techniques based upon the mechanics of natural selection [10] [11]. Pioneered in the 1970’s by John Holland [] and colleagues at the University of Michigan [19], GAs use the concept of “survival of the fittest” to determine, through successive generations of randomized, but directed, information exchange, the optimal sample value or point in a search space [10][11]. GAs offer a robust search mechanism as a priori knowledge is not generally required for successful application of the algorithm, and they have been successfully applied to a wide range of optimization problems [10]. The key operators of a GA are selection [10][11][20], crossover [10][11][21], mutation [10][11][22] and population size [10][11][23], with secondary parameters including variable encoding [10][11][24] and decoding [10][24], and
M.Eng
10
DCU
John P. Byrne (50222465)
GA -Optimisation of a Fuzzy Logic Controller
population-update [10][24], also having a bearing upon the effectiveness of the algorithm. Due to the stochastic nature of operation and the wide range of problems to which GAs may be applied, a formal, analytical description of the interactions and dependencies of the various parameters of a GA is complex, and consequently selection of GA parameters and associated settings, has to date been largely based upon empirical evaluation [25].
GAs can be used to optimize a FLC by optimizing the rule -base [26], membership functions [18], or knowledge base (i.e. both rule -base and membership functions) [18] [6]. For the GA-optimization of a rule-base, three different population strategies, known as Pittsburgh, Michigan and Iterative Rule are possible [18][27]. For the Michigan strategy, each GA chromosome in the population represents a single rule and so the population as a whole represents the entire rule -base, which is modified over time through interaction with the environment. The Pittsburgh strategy is to encode entire rule bases into each chromosome so that the entire population represents many competing rule -bases. The Iterative Rule strategy is similar to the Michigan approach, in the sense that single rules are found, but only the best individual member is considered to form part of the solution at each stage with the remaining population members discarded. Although the Pittsburgh approach involves more computational overhead [18], the competition among complete rule -bases, as opposed to single -rules, induces better cooperation among the rules of any proposed solution for the FLC [18]. In addition to choice of population strategy and all other GA parameters previously outlined, the form of objective function used in evaluating GA-population members is an essential factor of the optimization task [6]. In the realm of FLC optimization, numerous objective functions have been adopted based on minimizing particular attributes of the system response such as the Mean Square Error (MSE) [6], cost equations based on response rise and settling times [8] and integral of absolute error (IAE) [Visoli]. Irrespective of definition, the suitability of the objective function as a system performance indicator is critical to the successful application of a Genetic Algorithm and thus requires careful selection. Once constructed around a suitable objective function, the GA proceeds to evaluate candidate solutions using the objective function in order to gauge the performance of each potential solution when applied to the problem domain [26] [28].
Successful, and partially-
successful, solutions are rewarded by having “their genetic information” perpetuated to successive generations in the search for the optimal solution, while those potential solutions exhibiting poor performance are removed from “the gene-pool.”
M.Eng
11
DCU
John P. Byrne (50222465)
GA -Optimisation of a Fuzzy Logic Controller
Although robust and effective in terms of application to non-linear and optimization problems, the GA is a weak method in terms of learning ability and real-time operation [36]. However, enhanced synergy of GAs with fuzzy systems (FS) and neural networks (ANN) to form hybrid AI systems, will harness fully the strengths of each technique, thus providing GAs a niche role in future intelligent systems design. [36].
1.2.
Report Layout
In relation to work performed in this study, the remainder of the report consists of the following chapters; Chapter 2 presents a discussion on the structure of the simple genetic algorithm (SGA) as well as a brief overview of the theoretical basis of its operation, namely the Schema Theorem. Chapter 3 presents the motivation for, and analysis of, a parametric evaluation of the Simple Genetic Algorithm (SGA) that was performed in order to gain insight into appropriate parameter methods and settings that should be used for application of the SGA to the FLC optimisation problem. To ascertain if the GA-optimisation approach of fuzzy controllers used is valid, the performance of the GA-FLC was compared to that of a conventional, as well as a heuristically-tuned FLC, system model. Chapter 4 outlines the development and simulation of a the conventional position control model while chapter 5 discusses the development and simulation of the heuristic FLC (he-FLC)
Chapter 6 briefly discusses genetic fuzzy systems (GFS) and details the design of the SGA used to optimise the FLC and also outlines how MATLAB fuzzy inference systems (FIS) were used in conjunction with the GA to encode complete FLC rule -bases and membership function specifications. The chapter concludes with an evaluation of the results of the optimisation attempt and issues arising from it, through comparison with the conventional and heuristic FLC models.
The final chapter offers a summary and conclusions in respect of the project work.
M.Eng
12
DCU
John P. Byrne (50222465)
GA -Optimisation of a Fuzzy Logic Controller
2 Theory and Description of Genetic Algorithms. 2.1.
What are Genetic Algorithms?
Genetic Algorithms (GAs) are numerical optimization mechanisms based upon the mechanics of natural selection as exhibited in nature [10]. Pioneered in the 1970’s by John Holland and colleagues at the University of Michigan, GAs use the concept of “survival of the fittest” to determine, through successive generations of randomised information exchange, the optimal sample value or point in a search space. In the case of natural selection, individual entities of a species, better adapted to their environment, emerge as a result of successive chromosomal material exchange with other individual entities over several generations of the species. One therefore can view the process of natural selection as a continuous search mechanism that fully exploits historical information in order to identify the optimal chromosomal makeup of the species, with respect to its environment. GAs are the adaptation of this natural search process to numeric/geometric problem domains. Any search space can be described geometrically by the set of all n-tuple sample points, where n is the number of dimensions in the space. A priori knowledge of all such points, or a well-defined mathematical function of the search space, would facilitate identification of any sample point of particular interest, such as a global maxima or minima (though the techniques used may present significant computational overhead or may converge to local maxima or minima). In cases however where a priori knowledge of all sample points is absent or where the definition of the space cannot be expressed mathematically, the search for particular points of interest becomes non-trivial. It is in such cases that GAs find application. Sample points in a search space are coded by the GA as string data structures (binary, integer or real valued) [10] [11] [24] and are analogous to the basic genetic building block found in nature chromosomes. In cases where there is prior knowledge of some of the sample points, an initial population of chromosomes can be formed from the coding of the known sample points. In cases where no prior knowledge of any sample points within the search space is available, the initial population of chromosomes is formed through random generation. In either case, the population size is usually small by comparison to the complete set of chromosomes, representative of all points in the entire sample space. It follows that any search space of interest therefore, can be fully defined by the set of all such sample points (chromosomes), which geometrically defines the space.
M.Eng
13
DCU
John P. Byrne (50222465)
GA -Optimisation of a Fuzzy Logic Controller
Competition among individuals is abstracted as the evaluation of the fitness of each individual relative to the population as a whole. The fitter an individual, the higher its probability of being selected for reproduction
(i.e. perpetuation of its genetic information).
An individual (i.e.
information string) can be either a single decision variable (i.e. chromosome) coded as a string, or a concatena tion of several chromosomes within a single string where an optimisation solution consisting of multiple decision variables is required.
2.2.
GA Parameters
The simple GA (SGA) can be broken down into three distinct operations; • • •
Reproduction Crossover Mutatio n
The algorithm can be summarised as follows; begin t=0; initialise P(t) evaluate P(t) fitness P(t)
// establish initial population of strings // apply objective function to each string in P(t) // determine fitness of each string w.r.t. population as a whole
while termination condition not met do begin t=t+1
// increment generation
select P’(t+1) from P(t)
// form intermediate population of fittest members from P(t)
pair off and mate P’(t+1)
// mate individuals in P’(t+1) to produce offspring
evaluate offspring P’(t+1)
// apply objective function to offspring of P’(t+1)
fitness offspring P’(t+1)
// determine fitness of P’(t+1) offspring
update to P(t+1)
// establish P(t+1) population from fittest of P’(t+1)
end end
M.Eng
14
DCU
John P. Byrne (50222465)
GA -Optimisation of a Fuzzy Logic Controller
2.2.1. Initial Population The first step in the implementation of the SGA is to establish an initial population. The initial population will typically consist of 30–100 individual strings which in themselves represent potential solutions in the search for a global optima (e.g. maximum or minimum). Karr [17] suggests that for real-time applications a smaller population of typically 10 individuals should be used.
Depending on the target problem, each string in the population is either a coded single decis ion variable or a concatenation of several coded decision variables, and may be binary, integer or realvalued. While studies are ongoing as to the alphabets best suited to particular types of problems, binary valued strings are most commonly used. Whitley [11] suggests that the use of a minimal alphabet such as the binary alphabet maximises the number of hyperplane partitions sampled by the GA and therefore enhances the search. The use of real-valued strings can lead to greater algorithm efficiency since there is no requirement to convert between the coded representation (genotype) and the actual parameter value (phenotype). Also, improved computer technology allows greater floating-point precision and storage, which the algorithm could exploit. A further consideration is also the possible loss of resolution in the phenotype representation. However, the purpose of the GA being to identify an optimal solution (and not necessarily the absolute solution), allied to greater hyperplane sampling and simpler schemata counting arguments, makes the use of the binary alphabet commonplace in GA implementations [11].
Also research
suggests the use of Gray coding for populations (consistent Hamming distances between adjacent codes) in order to overcome the representational bias inherent in conventional binary coding and to allow the GA to refine solutions once the vicinity of the optimal solution is reached [37]. The use of integer or real valued codes is also possible. Once the coding decision is made, the initial population is typically established through random generation of the required number of strings. Thus for example, if M binary strings, each consisting of N bits, is required, then M x N random numbers universally distributed from the {0,1} alphabet are generated.
M.Eng
15
DCU
John P. Byrne (50222465)
GA -Optimisation of a Fuzzy Logic Controller
2.2.2. Evaluation of Population The evaluation of individuals within a GA population is a metric to determine the “closeness” of the decoded value (phentoype) of an individual string, to the global optimum being sought by the algorithm. With respect to the biological domain, evaluation is analogous to the fitness of an individual within a population of a species, relative to other individuals and the environment in which the species operates. In the natural world, the benefit accruing to fitter individuals is the attainment of more reproductive opportunities, which in turn, ensures perpetuation of their genetic material through successive generations. The degree of fitness attributed to an individual member of a species is not solely dependent upon exhibiting the many, and sometimes diverse, attributes which permit survival within a particular environment, but also upon the ability to exploit, more fully than its co-members, the resources of that environment. In the search for a global optimum within a space, GAs reduce the concept of fitness and competition to a performance metric through the application of an objective function to each member of a GA population, and, the subsequent evaluation of each objective function outcome relative to the population as a whole. The fitness of a GA string therefore is determined in two stages; (i)
determine string performance in the problem domain by application of an objective function.
(ii)
compare string performance to that of all other strings in the population to determine the relative fitness of the string.
The determination of a string’s fitness therefore can be viewed as follows; F(x) = g(f(x))
eqn. 1
where; F(x) is the fitness value of string x. f(x) is the objective function. g(x) is the transformation of performance to relative fitness. The definition of the objective function is problem-specific and, in conjunction with the coding decision, critical to the performance of the algorithm. The transformation of performance value to fitness highlights a number of issues that affect the performance of the algorithm.
M.Eng
16
DCU
John P. Byrne (50222465)
GA -Optimisation of a Fuzzy Logic Controller
2.2.3. Scaling and Offsets In the SGA, the measure of fitness of an individual is given by ratio performance value to the average performance value of the population as a whole i.e. f i
f
. While predominantly used, a
drawback to its use is that it can only be applied to non-negative values. In order therefore, to facilitate negative values, a linear transformation of the form;
F ( x ) = af ( x) + b
eqn. 2
is used where;
a represents a positive scaling factor b is an offset factor to ensure non-negative values. Linear scaling assigns reproductive opportunities in proportion to the fitness of an individual, and since there is no constraint placed upon the maximum number of copies of an individual that may be selected for reproduction (other than perhaps the population size), highly fit individuals in early generations may dominate the selection stage of the algorit hm. In such cases, the algorithm may converge to a false optima. In addition, if the difference in fitness values of a population is insignificant, then the linear scaling will only provide a small bias toward the fitter population members. This may result in the algorithm becoming sluggish and slow to converge. To counter these problems; •
An allocation of reproductive opportunities based upon the ranking of population members according, to their fitness, can be employed to avoid domination of the sele ction process by highly fit individuals at an early stage [24].
•
Logarithmic scaling can be used to increase deviation between the fitness values of population members, thus creating greater bias toward fitter individuals [24].
2.2.4. Selection Selection is the process whereby copies of population members are entered into an intermediate population group within which reproduction opportunities (trials) are assigned probabilistically. The number of copies of an individual selected for entry to the group is in proportion to the fitness of that individual relative to the population average fitness. Usually, but not always, the total number of
M.Eng
17
DCU
John P. Byrne (50222465)
GA -Optimisation of a Fuzzy Logic Controller
copies contained within the intermediate group is equal in number to the population from which they were selected. Selection can be considered to consist of three phases; (i)
Determination of the expected number of trials an individual can expect based on its relative fitness level. This is effectively the fitness evaluation stage as outlined above.
(ii)
Assignment of copies to the intermediate group (“Roulette Wheel” method).
(iii)
Random partner allocation of intermediate group members.
The first stage is effectively the use of the fitness evaluation of an individual for the purpose of determining the expected number of copies of that individual in the intermediate group, given the population size required for the intermediate group. The fitness value of an individual is in effect the probability of that individual being selected for the intermediate group in a single selection tria l (p select ). For an intermediate group population of n, the expected number of copies of the individual is estimated as n.pselect or in other words as the ratio of the fitness of the individual to the average fitness of the population. The second stage of the selection process is the use of p select in the actual assignment of membership to the intermediate group. This stage is more commonly referred to as “sampling”. Three performance criteria can be used to judge the suitability of a particular sampling process [24];
(i)
Bias
The absolute difference between the actual number of copies allocated membership to the intermediate group, and the expected number of copies, can highlight any bias introduced by the sampling process. The sampling stage of selection should be probabilistic and therefore any bias is undesirable. Zero bias is achieved when following an adequate number of trials, the expected number of copies is equal to the actual number of copies allocated membership to the intermediate group. (ii)
Spread
Spread is an indicator of consistency of the sampling process and is defined as the possible range of copies that an individual is allocated. If ac(i) = number of actual copies allocated then;
ac ∈ {eclower , echigher }
where eclower is the lower bound of the range and echigher is the higher bound of the range.
M.Eng
18
DCU
John P. Byrne (50222465)
GA -Optimisation of a Fuzzy Logic Controller
Spread is measured over a number of trials of the sampling process. Theoretical minimal spread is achieved when the range is such that zero bias is achieved, or in other words when; ec lower = echigher = number of actual copies = number of expected copies. (iii) Efficiency The time complexity of an algorithm is the amount of time (or number of operations) needed to complete the task. In general the upper bound time complexity of GA stages is of the order O(N x L) where N is equal to the number of individuals in the population and L is the length of an individual representation in bits [11]. The selection process therefore should be sufficiently efficient in order to maintain this level of time complexity. The implementation of the sampling stage of selection is predominantly based upon a “Roulette Wheel” method, of which there are a number of variants. In all implementations however the basic principle employed is to allocate all individuals, a representative occupancy of the wheel (intervals of a wheel or pie -chart), which is in proportion to their fitness. The “wheel”, which has a single pointer, is then spun n times, where n represents the required population size of the intermediate group. The inte rvals within which the pointer comes to rest on each spin, indicates the selection of the individual whose occupancy of the wheel spans that interval. The most commonly used Roulette Wheel methods are Stochastic Sampling with Partial Replacement (SSPR), Remainder Stochastic Sampling with Replacement (RSSR) and Stochastic Universal Sampling (SUS) [24]. Of these three methods, Stochastic Universal Sampling is a simpler implementation which exhibits zero bias, minimal spread and time complexity of order O(N). The SUS implementation can be best described as a multi-pointer Roulette Wheel that allocates wheel intervals to each individual in proportion to the fitness of the individual as described above. The number of pointers, n, is equal to the number of individuals required for the intermediate group, and therefore with a single spin of the wheel, the resting intervals of all n pointers selects the individuals for the intermediate group. In this way, those individuals with greater fitness are allocated larger intervals on the wheel and consequently are expected to have more copies selected to the intermediate group.
M.Eng
19
DCU
John P. Byrne (50222465)
GA -Optimisation of a Fuzzy Logic Controller
2.2.5. Crossover In nature, the genetic makeup of new species members (i.e. offspring) is a combination of chromosomes inherited from the offspring’s parents. The genotype of both parents consists of a complete set of alleles, each of which provides for a specific manifestation of the phenotypical attribute or feature that the particular allele governs. Offspring in general, only inherit alleles from either one parent or the other for each phenotypical attribute and in this way the genotype of the offspring consists of a mixture of inherited alleles from both parents, thus giving expression to a completely new phenotype. Evolution biases the selection of inherited alleles in the offspring genotype such that in each instance of allele inheritance from parents, the “stronger” allele, of the two, is selected.
A stronger allele is defined as one which will give an expression to the
phenotypical attribute which is better suited to the species environment. To therefore emulate the exchange of genetic information found in natural selection, a GA must; (i) (ii)
provide a method for the transfer of alleles between selected parent strings. ensure that the method preserves strong attributes in the offspring.
A GA emulates the process of genetic inheritance found in nature through an operation known as crossover (recombination). In its simplest form, crossover involves the random selection of a crossover site within a pair of selected, parent binary strings. The bits in each parent that lie between the crossover site and the end of the string are subsequently exchanged between parents, resulting in the generation of two offspring. For example parents
offspring
xxxxxxxxxxxxxxxx
x x x x x x x x x x x xyyyy
yyyyyyyyyyyyyyyy
y y y y y y y y y y y yxxxx
crossover site
Figure 1: Single-point crossover
M.Eng
20
DCU
John P. Byrne (50222465)
GA -Optimisation of a Fuzzy Logic Controller
This method is known as single-point crossover and figure 1 represents one method of information exchange for binary-valued strings, thus satisfying the first, of the desired requirements, listed above. Although relatively simple in terms of implementation, single -point crossover introduces a bias into the inheritance process. The bias relates to how the phenotype parameters are coded and the length of the resultant code.
Other methods of crossover for binary-valued strings as shown in figure 2, include multiple -point crossover and uniform crossover. Multiple -point crossover involves the random selection of two or more crossover sites and the subsequent exchange of bits that are located between crossover sitepairs (and/or between the last crossover site and the end of the string). An example of a 3-point crossover is illustrated below; offspring
parents
xxxxxxxxxxxxxxxx
xxxxxxxxyyyyyyxy
yyyyyyyyyyyyyyyy
yyyyyyyyxxxxxxyx
Figure 2: Multiple-point crossover (3-pt) The motivation behind the use of multiple-point crossover is that bits defining a strong attribute with respect to objective function evaluation, may not in fact be adjacent. Therefore in such instances, multiple -point crossover is more likely to preserve such strong attributes. In addition, the use of multiple -point crossover enhances the search as it forces the exploration of more regions within the search space than would be the case with single-point crossover. Uniform-crossover is a further crossover method for binary-valued strings which is a generalisation of multiple -point crossover technique. Uniform crossover basically renders each inter-bit site as a candidate for crossover-site selection. This involves the application of a randomly generated, binary mask which is equal in length to the parent strings. The value at each position in the mask determines from which parent the bit for the equivalent position in the offspring is inherited from. For example, in figure 3 the generation of a single offspring, through the application of uniformcrossover is illustrated where a 1 in the mask position indicates that the offspring inherits the corresponding bit from parent1 while a 0 indicates inheritance from parent2.
M.Eng
21
DCU
John P. Byrne (50222465)
GA -Optimisation of a Fuzzy Logic Controller
Parent1=x x x x x x x x x x x x x x x x Parent2=y y y y y y y y y y y y y y y y Mask = 0010100011010110
Offspring = y y x y x y y y x x y x y x x y Figure 3: Uniform crossover example If two offspring are required, then the complement of the mask may be used to generate the second offspring. Similar to multiple -crossover, the disruptive nature of uniform crossover forces increased exploration of the search space. In addition, with uniform crossover the perpetuation of sub-strings from parent to offspring is more likely to be based upon the contribution of each individual bit, in the sub-string, than to the performance of the sub-string as a whole. Uniform crossover therefore can make the algorithm’s performance less dependent upon the chosen coding scheme and length and may be more accurate in identification of the global optima. Shuffle crossover [24] counters the representational bias mentioned above, by shuffling the parental bit positions prior to application of single -point crossover, followed by unshuffling the bits in the offspring when crossover has been completed.
This method overcomes any introduced
representational bias but adds computational overhead since some form of bit-position memory must be employed in order to enable the re-sort following crossover. While the advantages of using multiple -point, uniform and shuffle crossover seem evident for binary genotypes, this is not to say that the use of single -point crossover is not preferred. Single -point crossover has the advantage of being a simpler implementation. Also in applications where some prior knowledge of the target problem is available, a better coding scheme, which may even exploit the bias, can be devised.
Finally, for optimisation or real-time problems consisting of large
populations, rapid convergence to a pareto-optimal solution may be preferrable to extended search for the global optima. For GAs operating on non-binary strings (integer or reals), other crossover methods such as Line and Intermediate recombination can be employed [24]. Both methods effectively restrict generation of offspring to the space defined by the parents. While the crossover methods outlined above provide a mechanism for the exchange of genetic information between strings, the requirement for the inheritance of strong genetic information from parent to offspring, leading to strong phenotypical attributes in the offspring, is not immediately
M.Eng
22
DCU
John P. Byrne (50222465)
GA -Optimisation of a Fuzzy Logic Controller
obvious from the descriptions of crossover given above. Consideration however of the role of GA schemata (see section 4.3 below) explains how a GA perpetuates strong genetic material through inheritance.
2.2.6. Mutation In natural selection, mutation is a stochastic process, which results in the genetic change of an allele within a chromosome. A new expression is therefore given to the phenotypical attribute governed by the chromosome, and more specifically, the allele. The consequence of the allele mutation may result in a phenotype which, relative to other phenotypes of the species, is less suited to its environment, more suited to its environment or which is equally suited to its environment (i.e. the mutation has no effect). In a GA, mutation is modelled by random application of allele change, with usually low probability (typically of order 0.01 – 0.001) and is usually considered to be a background operator in the GA.
The motivation for using mutation in a GA is twofold; (i)
Prevention of permanent loss of a particular allele. In populations, part icularly small ones, it is conceivable that every string in that population may have the same particular allele, set to the same value. This in effect means that the allele position of interest can never assume any other value in any subsequent generation and can result in premature convergence .
(ii)
Widen the exploration of the search space. The use of the mutation operator can direct the search to previously unexplored regions of the search space, thus leading to better solutions and a more robust algorithm.
M.Eng
23
DCU
John P. Byrne (50222465)
GA -Optimisation of a Fuzzy Logic Controller
2.2.7. Establishing the next GA-generation Any subsequent population may be overlapping or non-overlapping with respect to the current population P(t).
An overlapping population is one which includes members of the parental
population P(t) and some or all of the offspring of this parental generation. Overlapping populations are based upon relative fitness among parents and offspring and are sometimes referred to as “elitist”, indicating that strongly performing individuals progress through a number of generations. Non-overlapping populations are those populations where P(t) is completely replaced by offspring to form the next generation of P(t+1). In order to clarify the distinction between overlapping and nonoverlapping populations, a concept known as the generation gap, G, is used, where G=1 indicates non-overlapping, and 0 positive %if co=1, consequent sequence=: positive -> zero -> negative if (co==1) tbase=rot90(rot90(rbase)); rbase=tbase; end %update the rule-base (antecedent is of the form [e de]) rindx=0; %index into the rule-base for e=1:rnum for de=1:rnum rindx=rindx+1; rule_in(rindx).antecedent=[e,de]; rule_in(rindx).consequent=rbase(e,de); end end rule_out=rule_in;
M.Eng
192
DCU
John P. Byrne (50222465)
B4.4
GA -Optimisation of a Fuzzy Logic Controller
var_mfstrap.m
Summary: Subject to certain assumptions, this m-file generates a Matlab FIS membership functions definition given a 7-bit binary segment, a FIS fuzzy variable structure and a number defining the number of MFs for the particular variable in question. The membership functions are defined as trapezoidal but can assume a triangular shape by application of an offset value. In addition, application of a companding factor can effect non-even distribution of the membership functions and produce expansion (contraction) of central functions and vice versa for outer functions. Distribution of 3, 5, 7 and 9 MFs is possible and depends upon the value of input argument, rnum. Code Listing: % var_mfstrap (program to modify fuzzy variable membership functions) % Written: John P.Byrne Date: 10/08/03 % Takes a 7-bit GA-chromosome section (segment) to modify existing fuzzy variable's (var) MF specification. % The modified MF specification is then returned as a 1x3 structure array defining MF parameters. % Input argument, var, specifies whether input or output fuzzy variable MFs being processed. % MF_in is the flc_shell, while rnum is the rule-base size and thus specifies the number of MFs function mf_out=var_mfstrap(mf_in,segment,var,rnum) %split segment into fields; offset(3) and companding factor(3) offs=segment(1:3); compander=segment(4:7); %companding factor value %decode offset bits %decoding parameters used with function bs2rv dec_fld=[[3];0;0.1;1;0;1;1]; %convert binary segment to real value in range [0,0.1] using gray-decoding offs=bs2rv(offs,dec_fld); %decode companding factor dec_fld=[[4];0.5;2;1;0;1;1]; %convert binary segment to real value in range [0.5,2] using gray-decoding cf=bs2rv(compander,dec_fld); %for calculation of central MF locations and permissible MF offset step=3/(rnum+1); offset=(offs*(2*step)); %calculate permissible offset switch (rnum) case 3 mf_name=char('N','Z','P'); %look-up lists for MF name, type and size mf_type=char('trapmf','trapmf','trapmf'); %variable MF types all trapezoidal (shape modified by MF-params) mf_size=[4;4;4]; %size of MF parameter array for fuzzy variable case 5 mf_name=char('NB','NS','Z','PS','PB'); %look-up lists for MF name, type and size mf_type=char('trapmf','trapmf','trapmf','trapmf','trapmf'); %variable MF types trapezoidal mf_size=[4;4;4;4;4]; %size of MF parameter array for fuzzy variable
M.Eng
193
DCU
John P. Byrne (50222465)
GA -Optimisation of a Fuzzy Logic Controller
case 7 mf_name=char('NB','NM','NS','Z','PS','PM','PB'); %look-up lists for MF name, type and size %variable MF types all trapezoidal (shape modified by MF-params) mf_type=char('trapmf','trapmf','trapmf','trapmf','trapmf','trapmf','trapmf'); mf_size=[4;4;4;4;4;4;4]; %size of MF parameter array for fuzzy variable case 9 mf_name=char('NB','NMO','NMI','NS','Z','PS','PMI','PMO','PB'); %look-up lists for MF name, type and size %variable MF types all trapezoidal (shape modified by MF-params) mf_type=char('trapmf','trapmf','trapmf','trapmf','trapmf','trapmf','trapmf','trapmf','trapmf'); mf_size=[4;4;4;4;4;4;4;4;4]; %size of MF parameter array for fuzzy variable end %initialise MF type, name and parameter arrays for i=1:rnum; mf_in.mf(i).name=deblank(mf_name(i,:)); mf_in.mf(i).type=deblank(mf_type(i,:)); mf_in.mf(i).params=zeros(1,mf_size(i)); end switch rnum case 3 %calculate central points of N, and Z MFs for j=1:3 %check if mirror-image MFs have been specified if (j>2) %invert and swap N specifications to yield P specs oppmf=1; %default reassignment order for parameter array flip=[4 3 2 1]; %invert and 'flip' opposite MF parameters to get symmetrical MF parameters %negate opposite MF parameters tmp1=-(mf_in.mf(oppmf ).params); %'flip' the order of the elements tmp2(flip)=tmp1; %assign inverted and flipped array to opposite MF specification mf_in.mf(j).params=tmp2; else if ((j==1)&(var==1)) %NB data of input extreme fuzzy variable %centre point for evenly -dustributed MF centre=-1.5+((j)*step); %set default outer and inner-left values for extreme neg-MF mf_in.mf(j).params(1)=-2500; mf_in.mf(j).params(2)=-1500; %set inner-right value for relative to the centre and offset values mf_in.mf(j).params(3)=-(abs(centre+offset)^cf); %set outer-right value for relative to the centre and offset values mf_in.mf(j).params(4)=-(abs(centre+step-offset)^cf); else %not input fuzzy variable or non-extreme MF being defined centre=-1.5+((j)*step); %calculate central point for MF if (j==2) %Z-MF (has negative and positive components) mf_in.mf(j).params(2)=-(abs(centre-offset)^cf); %set inner-left for trapmf
M.Eng
194
DCU
John P. Byrne (50222465)
GA -Optimisation of a Fuzzy Logic Controller
mf_in.mf(j).params(3)=(centre+offset)^cf; mf_in.mf(j).params(1)=-(abs(centre-step+offset)^cf); mf_in.mf(j).params(4)=(centre+step-offset)^cf; else %for N or output variable mf_in.mf(j).params(2)=-(abs(centre-offset)^cf); mf_in.mf(j).params(3)=-(abs(centre+offset)^cf); mf_in.mf(j).params(1)=-(abs(centre-step+offset)^cf); mf_in.mf(j).params(4)=-(abs(centre+step-offset)^cf); end end end end
%set inner-right for trapmf %set outer-left position %set outer-right position
%set inner-left for trapmf %set inner-right for trapmf %set outer-left position %set outer-right position
case 5 %calculate central points of NB, NS and Z MFs for j=1:5 %check if mirror-image MFs have been specified if (j>3) %invert and swap NB and NS specifications to yield PB and PS specs if (j==4) %specify default MF params to copy to NS oppmf=2; else %specify default MF params to copy to NB oppmf=1; end flip=[4 3 2 1]; %default reassignment order for parameter array %invert and 'flip' opposite MF parameters to get symmetrical parameters tmp1=-(mf_in.mf(oppmf).params); %negate opposite MF parameters tmp2(flip)=tmp1; %'flip' the order of the elements %assign inverted and flipped array to opposite MF specification mf_in.mf(j).params=tmp2; else if ((j==1)&(var==1)) %NB data of input extreme fuzzy variable %centre point for evenly -dustributed MF centre=-1.5+((j)*step); %set default outer and inner-left values for (NB) ext. trapmf mf_in.mf(j).params(1)=-2500; mf_in.mf(j).params(2)=-1500; %set inner-right value for (NB) relative to the centre and offset values mf_in.mf(j).params(3)=-(abs(centre+offset)^cf); %set outer-right value for (NB) relative to the centre and offset values mf_in.mf(j).params(4)=-(abs(centre+step-offset)^cf); else %not input fuzzy variable or non-extreme MF being defined %calculate central point for MF centre=-1.5+((j)*step); if (j==3) %Z -MF (has negative and positive components) mf_in.mf(j).params(2)=-(abs(centre-offset)^cf); mf_in.mf(j).params(3)=(centre+offset)^cf; mf_in.mf(j).params(1)=-(abs(centre-step+offset)^cf); mf_in.mf(j).params(4)=(centre+step-offset)^cf;
M.Eng
195
%set inner-left for trapmf %set inner-right for trapmf %set outer-left position %set outer-right position
DCU
John P. Byrne (50222465)
GA -Optimisation of a Fuzzy Logic Controller
else %for NS and/or NB(output variable) mf_in.mf(j).params(2)=-(abs(centre-offset)^cf); mf_in.mf(j).params(3)=-(abs(centre+offset)^cf);
%set inner-left for trapmf %set inner-right for trapmf
mf_in.mf(j).params(1)=-(abs(centre-step+offset)^cf); %set outer-left position mf_in.mf(j).params(4)=-(abs(centre+step-offset)^cf); %set outer-right position end end end end case 7 %calculate central points of NB, NM, NS and Z MFs for j=1:7 %check if mirror-image MFs have been specified if (j>4) %invert and swap NB, NM and NS specifications to yield PB,PM and PS specs if (j==5) %specify default MF params to copy to NS oppmf=3; elseif (j==6) %specify default MF params to copy to NM oppmf=2; else %specify MF params to copy to NB oppmf=1; end flip=[4 3 2 1]; %default reassignment order for parameter array %invert and 'flip' opposite MF parameters to get symmetrical parameters tmp1=-(mf_in.mf(oppmf).params); %negate opposite MF parameters tmp2(flip)=tmp1; %'flip' the order of the elements %assign inverted and flipped array to opposite MF specification mf_in.mf(j).params=tmp2; else if ((j==1)&(var==1)) %NB data of input extreme fuzzy variable centre=-1.5+((j)*step); %centre point for evenly-distributed MF %set default outer and inner-left values for (NB) ext. trapmf mf_in.mf(j).params(1)=-2500; mf_in.mf(j).params(2)=-1500; %set inner-right value for (NB) relative to the centre and offset values mf_in.mf(j).params(3)=-(abs(centre+offset)^cf); %set outer-right value for (NB) relative to the centre and offset values mf_in.mf(j).params(4)=-(abs(centre+step-offset)^cf); else %not input fuzzy variable or non-extreme MF being defined centre=-1.5+((j)*step); %calculate central point for MF if (j==4) %Z-MF (has negative and positive components) mf_in.mf(j).params(2)=-(abs(centre-offset)^cf); %set inner-left for trapmf mf_in.mf(j).params(3)=(centre+offset)^cf; %set inner-right for trapmf mf_in.mf(j).params(1)=-(abs(centre-step+offset)^cf); %set outer-left position mf_in.mf(j).params(4)=(centre+step-offset)^cf; %set outer-right position else %for NS,NM and/or NB(output variable) mf_in.mf(j).params(2)=-(abs(centre-offset)^cf); %set inner-left for trapmf mf_in.mf(j).params(3)=-(abs(centre+offset)^cf); %set inner-right for trapmf mf_in.mf(j).params(1)=-(abs(centre-step+offset)^cf); %set outer-left position mf_in.mf(j).params(4)=-(abs(centre+step-offset)^cf); %set outer-right position
M.Eng
196
DCU
John P. Byrne (50222465)
GA -Optimisation of a Fuzzy Logic Controller
end end end end case 9 for j=1:9 %calculate central points of NB, NMO, NMI, NS and Z MFs if (j>5) %check if mirror-image MFs have been specified %invert and swap NB, NMO, NMI and NS specifications to yield PB, PMO, PMI and PS specs if (j==6) %specify default MF params to copy to NS oppmf=4; elseif (j==7) %specify default MF params to copy to NMI oppmf=3; elseif (j==8) %specify MF params to copy to NMO oppmf=2; else %specify MF params to copy to NB oppmf=1; end flip=[4 3 2 1]; %default reassignment order for parameter array %invert and 'flip' opposite MF parameters to get symmetrical parameters tmp1=-(mf_in.mf(oppmf).params); %negate opposite MF parameters tmp2(flip)=tmp1; %'flip' the order of the elements mf_in.mf(j).params=tmp2; %assign inverted and flipped array to opposite MF specification else if ((j==1)&(var==1)) %NB data of input extreme fuzzy variable centre=-1.5+((j)*step); %centre point for evenly-dustributed MF %set default outer and inner-left values for (NB) ext. trapmf mf_in.mf(j).params(1)=-2500; mf_in.mf(j).params(2)=-1500; %set inner-right value for (NB) relative to the centre and offset values mf_in.mf(j).params(3)=-(abs(centre+offset)^cf); %set outer-right value for (NB) relative to the centre and offset values mf_in.mf(j).params(4)=-(abs(centre+step-offset)^cf); else %not input fuzzy variable or non-extreme MF being defined centre=-1.5+((j)*step); %calculate central point for MF if (j==5) %Z -MF (has negative and positive components) mf_in.mf(j).params(2)=-(abs(centre-offset)^cf); mf_in.mf(j).params(3)=(centre+offset)^cf; mf_in.mf(j).params(1)=-(abs(centre-step+offset)^cf); mf_in.mf(j).params(4)=(centre+step-offset)^cf; else %for NS,NMO,NMI and/or NB(output variable) mf_in.mf(j).params(2)=-(abs(centre-offset)^cf); mf_in.mf(j).params(3)=-(abs(centre+offset)^cf); mf_in.mf(j).params(1)=-(abs(centre-step+offset)^cf); mf_in.mf(j).params(4)=-(abs(centre+step-offset)^cf); end end end end
%set inner-left for trapmf %set inner-right for trapmf %set outer-left position %set outer-right position %set inner-left for trapmf %set inner-right for trapmf %set outer-left position %set outer-right position
end %return structure mf_out=mf_in;
M.Eng
197
DCU
John P. Byrne (50222465)
Appendix C:
GA -Optimisation of a Fuzzy Logic Controller
The Schema Theorem
Considering first the effect on schema representation due to recombination. At time t; f(H) = average fitness of strings representative of schema, H. ⇒ f(H) = where
∑ f schema strings m(H, t)
∑ f schema strings = f(H) ⋅ m(H, t)
⇒
∑ f schema strings is the sum of fitness for strings representative of schema H.
m(H, t + 1) =
∑ f schema strings f
⇒
f(H) ⋅ m(H, t) f
where f is the average fitness of the population = ∴ m(H, t + 1) =
f(H) ⋅ m(H, t) f
= m(H, t)
∑fj n
f(H) f
In the case of increased representation, f(H) must be greater than f . Denoting the differnce as a stationary proportion of f , let f(H) = f + c f .
f +cf
⇒ m(H, t)(1 + c ) f Thus for discrete imcrements of time; at time = 1 ⇒ m(H,1) = m(H,0)(1 + c)
∴ m(H, t + 1) = m(H, t)
at time = 2 ⇒ m(H,2) = m(H,1)(1 + c) = m(H,0)(1 + c)(1 + c) = m(H,0)(1 + c) 2 etc. In general, increases in schema representa tion due to recombinat ion are given by; m(H, t) = m(H,0)(1 + c) t
eqn.1
From equation 1 above, the recombination strategy employed in a GA is the allocation of exponentially-increasing numbers of trials to schemata of above-average fitness. To complete the theorem, requires the effects of crossover and mutation to be factored in. ∂ (H) is the defining length of the schema (i.e. difference between first and last specified bit) O(H) is the order of the schema (i.e. number of specified bits) Pd = probabilit y of schema being destroyed by crossover (i.e. crossover site being within ∂ (H) ) ∴ Pd =
M.Eng
∂( H ) ∂ (H ) where L = string length ⇒ Psc = 1 − L −1 L −1
198
DCU
John P. Byrne (50222465)
GA -Optimisation of a Fuzzy Logic Controller
f(H) ∂( H ) ⋅ 1 − Pc where Pc = probabilit y occurring L − 1 f Mutation will destroy the schema if any of the schema bits are mutated. Pm = probabilit y of a bit being mutated ⇒ Psm = (1 − Pm ) Therefore m(H, t + 1) = m(H, t)
∴ Psurvive = (1 − Pm ) O ( H ) ≈ (1 − Pm ⋅ O( H )) for Pm