WORCESTER POLYTECHNIC INSTITUTE
    Computer Science Department

    CS4341 ❏ Artificial Intelligence ❏ A'06

    Mon, Tue, Thu, Fri - noon - AK 233
    Prof. David C. Brown, Fuller Lab 131, (508) 831-5618, dcb at cs.wpi.edu

    Version: Tue Oct 3 19:24:32 EDT 2006

    PROJECT 3 - A Genetic Algorithm Learning System

    Overview:

    The task is to write a simple Genetic Algorithm (GA) learning system that will take rules as input and will improve them. That is, the set of rules that result from GA processing should produce "better" results than the original rules. This requires some procedure for evaluating the quality of the result produced by a set of rules. This evaluation procedure is used to help guide the learning, causing rule sets which produce better results to be favored. Demonstrate that the GA works by using a given set of rules as input.

    Inspiration:

      Video

      "Kismet's facial expressions are generated using an interpolation-based technique over a three dimensional space. The three dimensions correspond to arousal, valence, and stance. These same three attributes are used to affectively assess the myriad of environmental and internal factors that contribute to Kismet's "emotional" state. We call the space defined by the [A, V, S] trio the affect space. The current affective state occupies a single point in this space at a time. As the robot's affective state changes, this point moves about within this space. Note that this space not only maps to emotional states (i.e., anger, fear, sadness, etc.) but also to the level of arousal as well (i.e., excitement and fatigue)."

    The Project:

    The goal of this project is to use a genetic algorithm to produce a high performance set of rules. For this project a set of rules is used to generate a configuration of movable "body parts", constituting a facial expression for Kismet, intended to correspond to a given emotional state. The four parts are ears, brows, lips, and jaw. Emotional states include, for example, tired, fear and joy. The best rule set produced, after using the GA as a sophisticated parallel search, will produce a configuration of part positions that correctly conveys every emotional state.

    A GA works on a population of candidate solutions (See Winston text Chapter 25). For this project an individual in the population is a rule set (i.e., a small set of IF-THEN rules). In each step of the GA activity new rule sets will be generated from the existing ones by crossover and mutation. Based on evaluations of quality, a fixed number of sets will be selected for survival through to the next generation. The process repeats itself from one generation to another until one or more rule sets with acceptable performance are generated.

    The relevant possible positions of the four movable parts are as follows:

    Ears Brows Lips Jaw coding
    Up Up Corners up Up/Closed 2
    Mid Mid Level Mid 1
    Down Down Corners down Down/Open 0

    The working memory (WM) which can describe the current state of the face has the following format:

    ((State  value-1)
     (Ears   value-2)
     (Brows  value-3)
     (Lips   value-4)
     (Jaw    value-5))
    
    where "State" is the emotional state and the other slots in the WM represent the positions of the corresponding parts. Value-1 can be one of {Tired, Content, Unhappy, Joy, Fear}, while value-2 to value-5 can each be one of {0, 1, 2}.

    The available predicates are (Tired?), (Content?), (Unhappy?), (Joy?), and (Fear?). Each tests the value of the State slot. So, for example, (Tired?) returns True if value-1 is "Tired", and False otherwise.

    The available actions are (Ears-are x), (Brows-are x), (Lips-are x), (Jaw-is x), where x is a value from {0, 1, 2}, and the result of each action is that the corresponding slot is set to the new value. So, for example, (Ears-are 2) sets the value 2 in the Ears slot in the WM.

    Based on these definitions, the five generic rules which determine body part positions in response to an emotional state are:

    (IF (Tired?)   THEN ((Ears-are a)(Brows-are b)(Lips-are c)(Jaw-is d)) )
    (IF (Content?) THEN ((Ears-are f)(Brows-are g)(Lips-are h)(Jaw-is i)) )
    (IF (Unhappy?) THEN ((Ears-are k)(Brows-are l)(Lips-are m)(Jaw-is n)) )
    (IF (Joy?)     THEN ((Ears-are p)(Brows-are q)(Lips-are r)(Jaw-is s)) )
    (IF (Fear?)    THEN ((Ears-are u)(Brows-are v)(Lips-are w)(Jaw-is x)) )
    

    Every rule set follows that general pattern. In an actual rule set the attribute values (e.g., q) are one of {0, 1, 2}.

    So, for example, a sample rule set might be:

    (IF (Tired?)   THEN ((Ears-are 0)(Brows-are 1)(Lips-are 2)(Jaw-is 1)) )
    (IF (Content?) THEN ((Ears-are 2)(Brows-are 0)(Lips-are 1)(Jaw-is 0)) )
    (IF (Unhappy?) THEN ((Ears-are 1)(Brows-are 2)(Lips-are 0)(Jaw-is 2)) )
    (IF (Joy?)     THEN ((Ears-are 0)(Brows-are 1)(Lips-are 2)(Jaw-is 1)) )
    (IF (Fear?)    THEN ((Ears-are 2)(Brows-are 0)(Lips-are 1)(Jaw-is 0)) )
    

    Your program must use the GA principles described in Chapter 25 of Winston's AI textbook.

    The genetic algorithm performs two types of transformations to rule sets -- mutation and crossover.

    • A mutation is defined by randomly selecting a rule from a rule set and changing one or two of its actions. This produces a new rule set. Randomly decide which of the four actions to change. Change that action by randomly changing its value to another allowable value: e.g., (Ears-are 0) is changed to (Ears-are 2). Decide whether to change another action. If yes, make the change. Then the mutation is complete.
    • A crossover involves two rule sets. This produces two new rule sets. A crossing point is selected in a random manner and the rules in the two sets which are beyond this point are interchanged. For example, if the crossing point is between rules 3 and 4, then rules 4 and 5 from the two sets are exchanged. This forms two new rules sets.

    Follow the general process shown in the text on page 524. The program should start with one rule set. That set is acted on by mutation (and crossover which does nothing) to form a second set. In each additional step you are supposed to generate, by using mutation and also crossover on the current generation, all possible new rule sets. Discard any duplicate rule sets that were already generated by this transformation process.

    Note that you apply a single mutation transformation to each member of the current population, to produce new rule sets. You also do crossovers between all possible pairs of the current rule sets, to produce new rule sets.

    The initial rule set in your population is the one where all attribute values are set to 1. That is:

    (IF (Tired?)   THEN ((Ears-are 1)(Brows-are 1)(Lips-are 1)(Jaw-is 1)) )
    (IF (Content?) THEN ((Ears-are 1)(Brows-are 1)(Lips-are 1)(Jaw-is 1)) )
    (IF (Unhappy?) THEN ((Ears-are 1)(Brows-are 1)(Lips-are 1)(Jaw-is 1)) )
    (IF (Joy?)     THEN ((Ears-are 1)(Brows-are 1)(Lips-are 1)(Jaw-is 1)) )
    (IF (Fear?)    THEN ((Ears-are 1)(Brows-are 1)(Lips-are 1)(Jaw-is 1)) )
    

    Evaluation of the quality of a facial expression would normally be done by a human. In this project we cheat (to drastically reduce run time) and simulate a human with a table of acceptable values. Each row in the table represents an acceptable resulting working memory given an initial State setting. Your fitness function will use this table.

    Tired 0 2 1 1
    Content 1 2 2 1
    Unhappy 0 2 0 2
    Joy 2 2 2 0
    Fear 1 2 1 0

    (Note that in this project you do not need to use the Rule Interpreter to determine the settings of the working memory for each rule set in the population, as the rules themselves provide that information. In general, of course, for rule set improvement systems this isn't true. Usually the rule set needs to be actually executed by the RI with an initial WM, and the resulting WM evaluated to determine what quality of solution that set produced. If the attribute values were not directly visible in the rules then you'd need to set State to Tired in the WM, then run the rules, and repeat that for each additional emotional state.)

    To determine the quality of a rule set, using the table, you must devise a measure which determines how well the rules produce values that a human would find acceptable.

    Only four rule sets should survive into the next generation. In order to select these four sets you need to use the rank-space method (p. 520) based on quality rank and diversity rank.

    • The quality rank will be based on the quality measure of each rule set.
    • The diversity rank can be determined once you have defined a distance function between two rule sets.

    Select the highest quality rule set to be the first to include in your next generation population. Compute the diversity rank of each set relative to the one selected. Select the next by combined rank. To select the third and fourth sets of rules compute the diversity rank relatively to the sets which already have been selected. You should break rank-sum ties by choosing the rule set with better diversity.

    In each case calculate the fitness and store it with the rules set in the new population. The fitness (probability) usually influence which rules sets take part in crossovers. Or, for this problem, you can try all of them, given that there are only four members in the population. As in the book, use p=0.66. The next fitness value will be 0.66 of the .33 that remains, and so on, for all four selections.

    The algorithm should stop after producing an acceptable rule set. In case no such set is produced, the algorithm should stop after a specified number of generations. You can determine that value by experimentation.

    Your program must produce an output file containing, in a condensed form, a record of the the rule sets selected in each generation with their corresponding quality measure, and quality and diversity ranks. A condensed rule set representation could be:

      0 2 1 1 / 1 2 2 1 / 0 2 0 2 / 2 2 2 0 / 1 2 1 0 / 10 / 1 / 1
    where each 4-tuple entry stands for the attribute values in the rule, the next entry is the quality measure, and the last two entries are the ranks.

    Submit

    You must submit:

    • On paper and via turnin:
      • Brief, clear documentation that describes the design of your GA system. What special algorithms or data structures were used?
      • A description of, and rationale for, your rule set quality measure.
      • A description of, and rationale for, your rule set diversity measure.
      • A description of, and rationale for, your stopping condition.

    • Via turnin only:
      • The code for the system (which must be well commented).
      • The clear, readable output from the test/demonstration runs. These should not be annotated as they should be self-explanatory. Given the possibly large amount of output you may want to have the demonstration output turn itself off after 1-2 populations. Normal output is still needed however.

    How to submit:

    • make sure that your name is associated with all items submitted

    • on paper: in class
    • via turnin: http://web.cs.wpi.edu/~kfisler/turnin.html


    Please note:

    1. Clearly label all printed work with your name and with the ID number provided by the TA.
    2. Clearly label each file with a helpful name.
    3. ZIP your entire project directory. Make sure it only contains the files to be submitted. Use "zip" and not some other compression tool.
    4. Name the file as your user name + "-proj3.zip"   For example, "clinton-proj3.zip"
    5. Submit the zipped project using web turnin.
    6. The project's turnin assignment name is "project3".
    Please let us know if you still have problems.