Presentation is loading. Please wait.

Presentation is loading. Please wait.

Character Artificial Intelligence CE00875-3 Finite State Automata Finite State Automata Lecture 3.

Similar presentations


Presentation on theme: "Character Artificial Intelligence CE00875-3 Finite State Automata Finite State Automata Lecture 3."— Presentation transcript:

1

2 Character Artificial Intelligence CE00875-3 Finite State Automata Finite State Automata Lecture 3

3 State Machines Why State Machines? What is a State Machine? Finite State Automata Finite State Machines Using FSMs Use in Game AI Advantages and Disadvantages Hierarchical State Machines

4 Why State Machines? The control code for reactive animats is basically just a large (possibly nested) if-elseif-else structure The control code for reactive animats is basically just a large (possibly nested) if-elseif-else structure These work okay for simple behaviour, but can become very difficult to write, read and debug when the animat needs to be more complex These work okay for simple behaviour, but can become very difficult to write, read and debug when the animat needs to be more complex A potentially better model for reactive control is some kind of state machine – though as we will see, it is not perfectly suited to reactive control A potentially better model for reactive control is some kind of state machine – though as we will see, it is not perfectly suited to reactive control State machines are widely used both in games and other kinds of intelligent software, so it is well worth studying State machines are widely used both in games and other kinds of intelligent software, so it is well worth studying

5 What is a State Machine? A state machine basically is a way of recognising or generating sequences of events in an orderly fashion A state machine basically is a way of recognising or generating sequences of events in an orderly fashion Some sequences are allowed and some are not eg telephone behaviour Some sequences are allowed and some are not eg telephone behaviour Formally, we say that transitions between the states are triggered by a sequence of input symbols from a defined alphabet. Formally, we say that transitions between the states are triggered by a sequence of input symbols from a defined alphabet. If a sequence of symbols is allowed by the mapping (state transition diagram) then the sequence is recognised, else it is rejected If a sequence of symbols is allowed by the mapping (state transition diagram) then the sequence is recognised, else it is rejected Alternatively, we might arrange to drive the system to generate output symbols from the states and/or on the transitions Alternatively, we might arrange to drive the system to generate output symbols from the states and/or on the transitions

6 Finite State Automata A FSA is a directed graph of nodes connected by arcs called transitions A FSA is a directed graph of nodes connected by arcs called transitions FSA can be used to represent classes of state-sequences by the connectivity of the transitions. Imagine a sequence of symbols from the alphabet {a,b,c} make the transitions FSA can be used to represent classes of state-sequences by the connectivity of the transitions. Imagine a sequence of symbols from the alphabet {a,b,c} make the transitions We always begin with the start state (1 – bold circle) and allow the sequence to control the transitions between states. If we end up in final acceptance state (4 - double circle), the sequence is accepted as a member of the class, (outputs a Boolean T); else, it is rejected We always begin with the start state (1 – bold circle) and allow the sequence to control the transitions between states. If we end up in final acceptance state (4 - double circle), the sequence is accepted as a member of the class, (outputs a Boolean T); else, it is rejected This FSA would accept the sequence abccca, but not the sequence abcbba. So the state machine can enforce a grammar – a certain syntax for expressions in a formal language This FSA would accept the sequence abccca, but not the sequence abcbba. So the state machine can enforce a grammar – a certain syntax for expressions in a formal language c a b c a 1 2 3 4 Final acceptance state Start state

7 Finite State Automata Formally, a FSA may be represented by as the quadruple Formally, a FSA may be represented by as the quadruple FSA = {Σ, Q, δ,F} where where – Σ is an input alphabet of symbols eg {a,b,c} – Q is a set of states eg {1,2,3,4} – δ is a transition function defined over Σ and Q eg state diagram – F is a subset of Q called accepting (terminal) states eg {4} One state, q 0, has a special meaning as the start state One state, q 0, has a special meaning as the start state δ is a function mapping the set of states Q and the input alphabet Σ onto the set of states: δ is a function mapping the set of states Q and the input alphabet Σ onto the set of states: – f(Q,Σ) → Q – This describes the connections in the transition network, as diagrammed by the graph in our example δ can also be represented as a table δ can also be represented as a table

8 FSA and Finite State Machines Similarly, the following FSA could classify sequences of actions as belonging to a class such as “Rocket jump” Similarly, the following FSA could classify sequences of actions as belonging to a class such as “Rocket jump” Fire Rocket Jump Look (down) 1 2 3 4 Rocket jump Start state Finite State Machines are different. While a FSA may only produce one output if a sequence of transitions is recognised, a FSM may produce output symbols at each transition, or each state Finite State Machines are different. While a FSA may only produce one output if a sequence of transitions is recognised, a FSM may produce output symbols at each transition, or each state Therefore, a FSM can be used to transduce a sequence of input symbols into a sequence of output symbols within a certain class Therefore, a FSM can be used to transduce a sequence of input symbols into a sequence of output symbols within a certain class One type of FSM called a Mealy machine outputs symbols at each transition, and are thus suitable for sequential control of actions One type of FSM called a Mealy machine outputs symbols at each transition, and are thus suitable for sequential control of actions

9 Mealy Machine So a Mealy machine may be formalised as for FSA, but requires an alphabet of output symbols, and a function to generate them from transitions So a Mealy machine may be formalised as for FSA, but requires an alphabet of output symbols, and a function to generate them from transitions FSM = {Σ, Q, Z, δ,λ} FSM = {Σ, Q, Z, δ,λ} where where Σ is an input alphabet of symbols eg {a,b,c} Σ is an input alphabet of symbols eg {a,b,c} Q is a set of states eg {1,2,3,4} Z is an output alphabet of symbols eg {x,y,z} δ is a transition function defined over Σ and Q eg state diagram λ is a function to determine the output symbol Z based on transitions There is a special start state but no special terminal state There is a special start state but no special terminal state The function λ computes an output symbol Z for each transition given the states Q and the input symbols Z ie f(Q,Σ) → Z The function λ computes an output symbol Z for each transition given the states Q and the input symbols Z ie f(Q,Σ) → Z

10 Mealy Machine b/z b/x c/z a/x 1 2 b/y c/x c/y 4 5 3 input symbol output symbol

11 Moore Machine A Moore machine has the same definition as a Mealy machine, but the function λ is simpler but less powerful A Moore machine has the same definition as a Mealy machine, but the function λ is simpler but less powerful FSM = {Σ, Q, Z, δ,λ} FSM = {Σ, Q, Z, δ,λ} where where Σ is an input alphabet of symbols eg {a,b,c} Σ is an input alphabet of symbols eg {a,b,c} Q is a set of states eg {1,2,3,4} Z is an output alphabet of symbols eg {x,y,z} δ is a transition function defined over Σ and Q eg state diagram λ is a function associating states Q with outputs Z The function λ maps states Q directly onto output symbols Z f(Q) → Z The function λ maps states Q directly onto output symbols Z f(Q) → Z

12 Moore Machine b b c a x b c a y y z input symbol output symbol

13 State: description of the internal settings of the machine, e.g. how much money has been depositied and not spent State: description of the internal settings of the machine, e.g. how much money has been depositied and not spent Finite states: 0, 25, 50, 75, 100, Finite states: 0, 25, 50, 75, 100, Rules: determine how inputs can change state Rules: determine how inputs can change state Example: Vending Machine

14 0255075100 000 001010 011 100 ret soda 100 25 Inputs 25 = 00 100 = 01 soda = 10 ret = 11

15 Example: Vending Machine state input new state S2 S1 S0 I0 I1 S2 S1 S0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 0 0 1 1 0 1 1 0 0 1 0 0 1 0 0 0 0 1 0 0 0 0 0 0 1 1 0 0 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 1 0 0 0 1 1 0 0 state input new state S2 S1 S0 I0 I1 S2 S1 S0 0 0 0 1 0 0 0 0 0 0 1 1 0 0 0 1 0 1 0 1 0 0 1 0 0 1 1 1 0 0 0 0 1 0 0 1 0 0 0 1 0 0 0 1 1 0 0 0 0 0 1 1 1 0 0 0 0 1 0 1 1 0 0 0 0 1 1 1 1 0 0 0 1 0 0 1 1 0 0 0

16 Example: Vending Machine state input new state S2 S1 S0 I0 I1 S2 S1 S0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 0 0 1 1 0 1 1 0 0 1 0 0 1 0 0 0 X 1 0 0 0 0 0 0 1 1 0 0 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 state input new state S2 S1 S0 I0 I1 S2 S1 S0 0 0 0 1 0 0 0 0 0 0 1 1 0 0 0 1 0 1 0 1 0 0 1 0 0 1 1 1 0 0 0 0 1 0 0 1 0 0 0 1 X X X 1 1 0 0 0

17 Using FSMs There are other types of FSMs too, such as Augmented Transition Networks (ATNs). These are commonly used where efficient parsing of complex patterns of symbols must be recognised, such as in the natural language processing There are other types of FSMs too, such as Augmented Transition Networks (ATNs). These are commonly used where efficient parsing of complex patterns of symbols must be recognised, such as in the natural language processing Patterns of symbols such as abccca which belong to a class acceptable to a FSM are called regular expressions or regular languages. The FSM enforces the grammar of a given expression/language Patterns of symbols such as abccca which belong to a class acceptable to a FSM are called regular expressions or regular languages. The FSM enforces the grammar of a given expression/language Such state machines may be used to parse regular expressions making up an artificial language, such as Java or C. Such state machines may be used to parse regular expressions making up an artificial language, such as Java or C. They may also be used to parse sentences in a natural language, such as French. This could produce a syntactical parse tree, a breakdown of the linguistic components such as noun phrase, verb phrase, articles, etc. They may also be used to parse sentences in a natural language, such as French. This could produce a syntactical parse tree, a breakdown of the linguistic components such as noun phrase, verb phrase, articles, etc.

18 Use in Game AI Although State Machines are very widely used in actual game code, they are rarely as pure as the FSA or FSM of theory. Although State Machines are very widely used in actual game code, they are rarely as pure as the FSA or FSM of theory. You can use FSAs to recognise actions of another player eg observing enemy basic enemy acts, and recognising sequences as belonging to a strategy, or other high level description for decision- making You can use FSAs to recognise actions of another player eg observing enemy basic enemy acts, and recognising sequences as belonging to a strategy, or other high level description for decision- making You can use FSMs to organise complex sequences of behaviour, by making the transitions be triggered by perceptual events in the world, while arranging for states to order procedures calling action functions You can use FSMs to organise complex sequences of behaviour, by making the transitions be triggered by perceptual events in the world, while arranging for states to order procedures calling action functions

19 Advantages/Disadvantages of FSMs Pros Pros –Very simple, easy to visualise –Efficient implementation is possible –Theory is well-founded and well understood, algorithms off-the- shelf –Proven popular in computer games and for control of sequences, parsing of artificial and natural languages Cons Cons –Large state machines can become complex to debug –Computationally limited to certain class of problems (regular exp) –The design of a FSM is fixed at design-time, not dynamic –Possible procedural control problems due to sequential chaos, loss of data, and flow of control

20 Designing a RCS using State Machine Begin by listing your Begin by listing your –1) inputs (perceptual tests – eg if(sight < 5.0)...) –2) states (eg avoid, wander, attack, flee, etc.) –3) outputs (eg hurl grenade, drop gun, eat food) –Draw a state transition diagram representing your machine Actions are represented by procedures within the states that call basic output functions in the game eg run(), turn(), watch() etc. Actions are represented by procedures within the states that call basic output functions in the game eg run(), turn(), watch() etc.

21 Question: Where should state transitions be processed? Maybe things change while we’re inside a state procedure, so we should test for updates in there as well as ‘outside’? But this leads to redundancy and loss of performance Question: Where should state transitions be processed? Maybe things change while we’re inside a state procedure, so we should test for updates in there as well as ‘outside’? But this leads to redundancy and loss of performance So, procedures within a state should be atomic – ie once a state has been entered, nothing may interrupt the flow of control for that action So, procedures within a state should be atomic – ie once a state has been entered, nothing may interrupt the flow of control for that action

22 Designing A RCS using State Machine Ideally, a reactive system has inputs processed in parallel. Can’t do this with a state machine, whose inputs are sequences of symbols - still rely on a sequence of tests to trigger transitions Ideally, a reactive system has inputs processed in parallel. Can’t do this with a state machine, whose inputs are sequences of symbols - still rely on a sequence of tests to trigger transitions There is the question of priorities – we need to ensure that high priority tests get done first, so that their transitions can get in first There is the question of priorities – we need to ensure that high priority tests get done first, so that their transitions can get in first There is also the problem of loss of data, since events are happening in real time; might get two important events yet we can only process one at a time There is also the problem of loss of data, since events are happening in real time; might get two important events yet we can only process one at a time Possible solution – keep tests inside a simplified if-elseif-else structure. Have it generate symbols which are then enqueued onto a short queue Possible solution – keep tests inside a simplified if-elseif-else structure. Have it generate symbols which are then enqueued onto a short queue A queue is a First In, First Out (FIF0) data structure. At each perceive-act cycle, the next item in the queue is taken off for processing the transitions to arrive at a state. A queue is a First In, First Out (FIF0) data structure. At each perceive-act cycle, the next item in the queue is taken off for processing the transitions to arrive at a state.

23 Designing A RCS using State Machine If (test1) enqueue(o) else if (test2) enqueue(a) else if (test3) enqueue(f) else enqueue (w) dequeue (next) process state transitions execute state procedure 2. next symbol makes transition in state machine 3. state procedures generate actions w f o a 1. perceptual test enqueues an input symbol symbols move in this direction buffer length of 4

24 Hierarchical State Machines But how can we deal with the problem that complex state machines can be just as difficult to write, debug and modify as other designs But how can we deal with the problem that complex state machines can be just as difficult to write, debug and modify as other designs One approach is the concept of hierarchical state machines One approach is the concept of hierarchical state machines Consider the machine at more than one level, with the levels themselves related by transitions Consider the machine at more than one level, with the levels themselves related by transitions Divide the complexity into parts and have a related set of states - or even a whole nested state machine – regarded from the top level as a single state Divide the complexity into parts and have a related set of states - or even a whole nested state machine – regarded from the top level as a single state a b zoom in zoom out a b Abstract Refined

25 Emotive States; Emotive Bot Emotions and Computers Emotions and Computers A Model of Emotions A Model of Emotions Emotional Expression for Communication Emotional Expression for Communication Affective Model for Bots Affective Model for Bots Sensations, Emotions, Moods and Feelings Sensations, Emotions, Moods and Feelings Portraying Emotions in Games Portraying Emotions in Games An Extensible Affective System An Extensible Affective System Processing Sensations & Emotions Processing Sensations & Emotions The Affective System Put Together The Affective System Put Together

26 Emotions and Computers The idea of computers with emotions may seem strange because i) our culture separates emotions and logic and ii) associates computers with logic The idea of computers with emotions may seem strange because i) our culture separates emotions and logic and ii) associates computers with logic Yet the truth is that models of emotions have been built from the earliest days of AI and “affective computing” is by now a well- established subfield Yet the truth is that models of emotions have been built from the earliest days of AI and “affective computing” is by now a well- established subfield There could be many advantages in making machines cable of having emotions, or at least recognising them in humans and reacting properly There could be many advantages in making machines cable of having emotions, or at least recognising them in humans and reacting properly In nouvelle game AI, we are interested in making emotional animats for the same reason as story-tellers – because this will enhance the realism of non-player characters, make them more entertaining and help to more fully engage players with them In nouvelle game AI, we are interested in making emotional animats for the same reason as story-tellers – because this will enhance the realism of non-player characters, make them more entertaining and help to more fully engage players with them A lot of interesting philosophical questions flow from the idea of emotional computers A lot of interesting philosophical questions flow from the idea of emotional computers

27 A Model of Emotions Plutchick (1980) described eight primary emotions organised into pairs of states. In this model, it is impossible to experience the two states of a pair at once. The overall emotional status is registered by degrees of arousal of one of each pair Plutchick (1980) described eight primary emotions organised into pairs of states. In this model, it is impossible to experience the two states of a pair at once. The overall emotional status is registered by degrees of arousal of one of each pair Each state has a degree of intensity and a target object or state of affairs to which it refers Each state has a degree of intensity and a target object or state of affairs to which it refers Each state has behavioural implications which betray its “purpose” in helping the organism survive Each state has behavioural implications which betray its “purpose” in helping the organism survive causes rejection of the target object or state of affairs/produces aversive signal for learning FEAR | ANGER ACCEPTANCE | DISGUST JOY | SORROW ANTICIPATION | SUPRISE recruits energy and directs destructive force toward an obstacle flags unexpected event/ directs attention to percepts/ raises heart rate releases hormones, tensions muscles and prepares for fight or flight recruits energy and produces reinforcing signal for learning withholds energy, forces withdrawal to safety and produces aversive signal for learning tolerates target object or state of affairs/produces reinforcing signal for learning allows preparation for expected event/ tests model of the world

28 A Model of Emotions The Plutchik model allows states to combine to produce compound “flavours” of emotion. Eg sorrow + suprise = disappointment; fear + acceptance = submission, etc. The Plutchik model allows states to combine to produce compound “flavours” of emotion. Eg sorrow + suprise = disappointment; fear + acceptance = submission, etc. The model presupposes perceptual, learning and cognitive systems, but says little about them The model presupposes perceptual, learning and cognitive systems, but says little about them Since emotions are closely tied to sensors, effectors and bodily interaction in the world, it follows that embodied AI might be useful at providing these as a more complete system than traditional AI models, which had to work on disembodied computers Since emotions are closely tied to sensors, effectors and bodily interaction in the world, it follows that embodied AI might be useful at providing these as a more complete system than traditional AI models, which had to work on disembodied computers Generally speaking, affective models of this kind try to mimic the different basic functions of emotions: regulation of behaviour, learning and communication Generally speaking, affective models of this kind try to mimic the different basic functions of emotions: regulation of behaviour, learning and communication Plutchik’s model is an example of how emotional states might signal survival-related classes of stimuli and how this could regulate action Plutchik’s model is an example of how emotional states might signal survival-related classes of stimuli and how this could regulate action

29 Emotional Expression for Communication Emotion has an important role in dealing with others Emotion has an important role in dealing with others Being able to read the emotional state of another human would have powerful survival implications, and hence be selected for in human evolution Being able to read the emotional state of another human would have powerful survival implications, and hence be selected for in human evolution Being able to influence the emotional state of another human would also be very useful Being able to influence the emotional state of another human would also be very useful Humans signal their emotional states by universal expressions, and we can read these in other humans Humans signal their emotional states by universal expressions, and we can read these in other humans It could be useful to have computers or robots do this: It could be useful to have computers or robots do this: - vision systems could read human facial expressions and classify them as emotions - vision systems could read human facial expressions and classify them as emotions - graphical or robot faces could have their features set into universal expressions to signal emotions

30 Emotional Expression for Communication Emotions can also be expressed in (and read from) gestures Emotions can also be expressed in (and read from) gestures Over a longer time frame, emotions can be expressed in (and read from) behaviours Over a longer time frame, emotions can be expressed in (and read from) behaviours Emotions may also be communicated via language: Emotions may also be communicated via language: - choice of words may be influenced by emotional state - choice of words may be influenced by emotional state - pitch, tone, speed and loudness of voice carries affective information - pitch, tone, speed and loudness of voice carries affective information This means that an emotional system needs to interact with other behavioural control mechanisms and influence them according to the current emotional state of the system This means that an emotional system needs to interact with other behavioural control mechanisms and influence them according to the current emotional state of the system So research on these areas often overlaps with the study of realistic body animation, including facial expression, mannerisms, natural language generation and speech synthesis So research on these areas often overlaps with the study of realistic body animation, including facial expression, mannerisms, natural language generation and speech synthesis

31 Sensations Emotions in embodied creatures begin with sensations. In this model, a sensation will be defined as an immediate reaction to a creature’s current situation Emotions in embodied creatures begin with sensations. In this model, a sensation will be defined as an immediate reaction to a creature’s current situation They might include surprise, anticipation, disgust, attraction, pain and pleasure They might include surprise, anticipation, disgust, attraction, pain and pleasure Sensations are visceral “gut reactions” – they happen almost instantaneously, and do not last very long. They may arise from two different sources: Sensations are visceral “gut reactions” – they happen almost instantaneously, and do not last very long. They may arise from two different sources: Sensations from Perceptions – The body detects a certain class of stimuli from the environment, which causes an immediate short term reaction eg sensation of surprise if a player or NPC appears suddenly Sensations from Perceptions – The body detects a certain class of stimuli from the environment, which causes an immediate short term reaction eg sensation of surprise if a player or NPC appears suddenly Sensations from Cognition – A mental state may also cause a sensation. For example, the thought of blood might cause a sensation of disgust Sensations from Cognition – A mental state may also cause a sensation. For example, the thought of blood might cause a sensation of disgust

32 Emotions Higher-level and longer-lasting affective trends are called emotions in this model. An emotion is a lasting characteristic of a persons affective state Higher-level and longer-lasting affective trends are called emotions in this model. An emotion is a lasting characteristic of a persons affective state Emotions might include fear, anger, joy and sorrow Emotions might include fear, anger, joy and sorrow Emotions change slowly compared to sensations. Emotions could be triggered by a single sensation, or by multiple sensations Emotions change slowly compared to sensations. Emotions could be triggered by a single sensation, or by multiple sensations Champardard calls basic dimensions (such as fear, anger etc) primary emotions. Each may have various degrees of intensity, which Champandard calls secondary emotions (?) Champardard calls basic dimensions (such as fear, anger etc) primary emotions. Each may have various degrees of intensity, which Champandard calls secondary emotions (?) Eg the primary emotion of fear might have a low intensity (apprehension) or a high intensity (terror) Eg the primary emotion of fear might have a low intensity (apprehension) or a high intensity (terror) As with Plutchik’s model, some might be mutually antagonistic eg As with Plutchik’s model, some might be mutually antagonistic eg joy and sorrow. These are called complementary emotions. joy and sorrow. These are called complementary emotions.

33 Moods Now a creature’s mood will be defined as its complete set of emotions at a particular time Now a creature’s mood will be defined as its complete set of emotions at a particular time This will be represented as a set of primary emotions, each with its own intensity This will be represented as a set of primary emotions, each with its own intensity A positive mood might include acceptance, satisfaction (moderate amount of joy) and awe (high level of surprise) A positive mood might include acceptance, satisfaction (moderate amount of joy) and awe (high level of surprise) Moods thus include complex emotions, which are subsets of primary emotions Moods thus include complex emotions, which are subsets of primary emotions

34 Feelings Affective states can refer to an object or event (even one remembered in the past or anticipated in the future) Affective states can refer to an object or event (even one remembered in the past or anticipated in the future) In Champadard’s model, these are called feelings In Champadard’s model, these are called feelings Feelings are persistent associations between an emotion and a (class of) object Feelings are persistent associations between an emotion and a (class of) object Examples are cruelty (to dogs), love (of a brother), hatred (of pirates) Feelings do not depend on the current state of the creature, but may refer to past or present (or even hypothetical) states of affairs

35 Portraying Emotions in Games How could an observer see the effects of emotional states in an animat which had them? How could an observer see the effects of emotional states in an animat which had them? Many games (certainly FEAR/Quake2) have little, if any provision for controlling facial expressions well enough to signal emotions that way (The action is usually too fast to see the faces close up anyway) Many games (certainly FEAR/Quake2) have little, if any provision for controlling facial expressions well enough to signal emotions that way (The action is usually too fast to see the faces close up anyway) However, recall that emotions can also be communicated by actions and language However, recall that emotions can also be communicated by actions and language Existing actions can be triggered or changed by affective state. Eg, terror might cause the animat to wail, or depression might cause it walk more slowly than usual Existing actions can be triggered or changed by affective state. Eg, terror might cause the animat to wail, or depression might cause it walk more slowly than usual A lack of action might also signify something: eg failing to respond to attack might be a sign of submission. Higher level decisions, even at the strategic level, might also reveal emotions in some circumstances A lack of action might also signify something: eg failing to respond to attack might be a sign of submission. Higher level decisions, even at the strategic level, might also reveal emotions in some circumstances

36 Portraying Emotions in Games Existing gestures such as Flipoff() may be used to signify (anger) Existing gestures such as Flipoff() may be used to signify (anger) Champandard describes a general-purpose interface to the enumerated action functions of the Quake 2 engine void Gesture ( const GestureType g ); Champandard describes a general-purpose interface to the enumerated action functions of the Quake 2 engine void Gesture ( const GestureType g ); Senses indirectly play a role in the portrayal of emotions, because they are closely linked to action – especially in reactive models Senses indirectly play a role in the portrayal of emotions, because they are closely linked to action – especially in reactive models A good example is anticipation, which has the effect in real creatures of heightening sensory awareness. The thresholds at which stimuli signifying possible danger are detected are lower than usual in this state A good example is anticipation, which has the effect in real creatures of heightening sensory awareness. The thresholds at which stimuli signifying possible danger are detected are lower than usual in this state Chat communications can also be used to make language signify emotions eg Say() or SayTeam() functions Chat communications can also be used to make language signify emotions eg Say() or SayTeam() functions void Say ( const string& text, const GroupType g = everybody ); void Say ( const string& text, const GroupType g = everybody );

37 Portraying Emotions in Games Some affective behaviour scenarios: Some affective behaviour scenarios: - Joy: dance or jump - Joy: dance or jump - Fear: faster but less accurate turns than usual; run faster - Fear: faster but less accurate turns than usual; run faster - Extreme fear: stop thinking and freeze for a while - Extreme fear: stop thinking and freeze for a while - Disgust: turn away from reference stimulus; say “ugh” - Disgust: turn away from reference stimulus; say “ugh” - Anticipation: swing gun wildly at any sound; slower walking than usual - Anticipation: swing gun wildly at any sound; slower walking than usual Extra touches for very emotive characters Extra touches for very emotive characters - Insult enemies during battle; perform taunting gestures - Insult enemies during battle; perform taunting gestures - Run away screaming when the enemy is powerful - Run away screaming when the enemy is powerful - Keep a history of conflict, and target enemy based on grudges - Keep a history of conflict, and target enemy based on grudges

38 An Extensible Affective System Champandard designs an affective system for FEAR animats that Champandard designs an affective system for FEAR animats that - is based on the model described so far (and the Plutchick psychoevolutionary model) - is based on the model described so far (and the Plutchick psychoevolutionary model) - uses a FEAR finite state automata/machines module - uses a FEAR finite state automata/machines module - works with other behavioural control architectures (since emotions are only part of a functioning cognitive system) and can be enhanced - works with other behavioural control architectures (since emotions are only part of a functioning cognitive system) and can be enhanced Simplified: only models four primary emotions: fear/anger, surprise/anticipation. These are complementary states, so one should observe no more than two at any time Simplified: only models four primary emotions: fear/anger, surprise/anticipation. These are complementary states, so one should observe no more than two at any time Simplified: each emotion is represented as a binary value: either fully activated or inactive (no secondary emotional levels here) Simplified: each emotion is represented as a binary value: either fully activated or inactive (no secondary emotional levels here) Simplified: emotional states merely raise or lower the effectiveness of existing reactive behaviours Simplified: emotional states merely raise or lower the effectiveness of existing reactive behaviours

39 FEAR’s FSA/FSM Module The FEAR platform allows both Finite State Automata (recognisers, acceptors, parsers) and Finite State Machines (transducers) to be easily and efficiently implemented The FEAR platform allows both Finite State Automata (recognisers, acceptors, parsers) and Finite State Machines (transducers) to be easily and efficiently implemented FSA – inputs are a sequence of symbols (eg from an vector of characters) which can trigger the state transitions. The output can be any kind of data, but usually sets a categorical variable (for classification) or a Boolean variable (for acceptance): FSA – inputs are a sequence of symbols (eg from an vector of characters) which can trigger the state transitions. The output can be any kind of data, but usually sets a categorical variable (for classification) or a Boolean variable (for acceptance): bool Accept ( const vector & sequence ); bool Accept ( const vector & sequence ); Symbol Recognise( const vector & sequence ); Symbol Recognise( const vector & sequence ); FSM – one output for each input, so you need to either step a single symbol in and out, or else run an entire set of symbols and get a matching output set: FSM – one output for each input, so you need to either step a single symbol in and out, or else run an entire set of symbols and get a matching output set: Symbol Tick ( const Symbol in ); Symbol Tick ( const Symbol in ); void Simulate(const vector & in vector & out ); void Simulate(const vector & in vector & out );

40 Processing Sensations Sensations will be simply perceived classes of objects or events in the environment, such as unexpected sounds, blood splats or explosions (cognitive sensations are not addressed in this prototype) Sensations will be simply perceived classes of objects or events in the environment, such as unexpected sounds, blood splats or explosions (cognitive sensations are not addressed in this prototype) A simple FSA, used as a recogniser, will accept perceptions or sequences of perceptions and move into a state representing the current sensation, at each Think cycle A simple FSA, used as a recogniser, will accept perceptions or sequences of perceptions and move into a state representing the current sensation, at each Think cycle Anger/anticipation Anger/surprise Fear/surprise Fear/anticipation expected damage unexpected sound explosion item picked up fa fs as aa

41 Processing Emotions The mood of the system may be in any of four states, each consisting of a pair of (non-complementary) emotions. This enforces the constraint that complementary emotions may not be expressed at the same time The mood of the system may be in any of four states, each consisting of a pair of (non-complementary) emotions. This enforces the constraint that complementary emotions may not be expressed at the same time The moods are fully interconnected, so sensations from the sensation FSA may move the system from any mood to any other The moods are fully interconnected, so sensations from the sensation FSA may move the system from any mood to any other fear/surprise fear/anticipation anger/surprise anger/anticipation fa aa fs fa fs as aa fa as aa fs Each state will output an associated change in the parameters used to control accuracy and power of actions; and the delay and precision of perceptual functions...

42 Emotional Output Accuracy is the randomness or error of an action: 1.0 means the commanded action is performed perfectly; 0.0 means the action is randomised Accuracy is the randomness or error of an action: 1.0 means the commanded action is performed perfectly; 0.0 means the action is randomised Power is used to scale the magnitude of the action: 1.0 means the actions have their maximal value 0.0 means the action is frozen Power is used to scale the magnitude of the action: 1.0 means the actions have their maximal value 0.0 means the action is frozen Delay alters perceptions. A delay of n means n seconds pass before a stimuli is recognised by perceptual functions Delay alters perceptions. A delay of n means n seconds pass before a stimuli is recognised by perceptual functions Precision alters the location of objects in space by perceptual functions. A value of 1 means the position is exact; while 0 means that a large random number is added to the distance and angle Precision alters the location of objects in space by perceptual functions. A value of 1 means the position is exact; while 0 means that a large random number is added to the distance and angle Precision = 0.7 Power = 0.2 Delay = 0.0 Accuracy = 0.9 Precision = 0.9 Power = 0.4 Delay = 1.0 Accuracy = 0.2 Precision = 0.0 Power = 1.0 Delay = 0.3 Accuracy = 0.8 Precision = 0.1 Power = 0.9 Delay = 0.8 Accuracy = 0.3 surprise anticipation fear anger

43 Affective System Put Together affecting all actions and perceptions sensation pattern of parameters emotion FSM sensation FSA cycle of perceptions At each Think cycle a (possibly new) sensation may arise in the sensation FSA if it reaches an end state At each Think cycle a (possibly new) sensation may arise in the sensation FSA if it reaches an end state New sensations are passed asynchronously to the emotion FSM, which may change state to a new mood New sensations are passed asynchronously to the emotion FSM, which may change state to a new mood Each mood outputs its characteristic parameters which in turn affect both actions and perceptions Each mood outputs its characteristic parameters which in turn affect both actions and perceptions

44 Evaluation of Affective System This design is (partly) implemented in the Moody animat This design is (partly) implemented in the Moody animat The alterations to action and perceptual parameters do make a difference to the animat’s behaviour, but it is subtle and you need observe carefully to see the effects The alterations to action and perceptual parameters do make a difference to the animat’s behaviour, but it is subtle and you need observe carefully to see the effects It would be possible to make the emotional system output more dramatic behaviour - easier to see, but possibly inappropriate at times It would be possible to make the emotional system output more dramatic behaviour - easier to see, but possibly inappropriate at times Errors in perception and changes in speed of response are realistic emotional effects and do lead to game events which wouldn’t happen otherwise Errors in perception and changes in speed of response are realistic emotional effects and do lead to game events which wouldn’t happen otherwise System is simple to adjust (though not as simple as Ch suggests) System is simple to adjust (though not as simple as Ch suggests) Transitions are all boolean – states do not rise and fall in degree, so no “secondary emotions” are possible. Also the emotions do not change Transitions are all boolean – states do not rise and fall in degree, so no “secondary emotions” are possible. Also the emotions do not change Emotional states have no “hysteresis”, meaning they can change as fast as sensations – not true to the model Emotional states have no “hysteresis”, meaning they can change as fast as sensations – not true to the model

45 Summary The recognition and production of emotions in computers is possible, and there are many reasons to wish to do so The recognition and production of emotions in computers is possible, and there are many reasons to wish to do so In nature, emotions regular behaviour, assist learning and allow communication to other organisms In nature, emotions regular behaviour, assist learning and allow communication to other organisms Plutchick’s model of emotion specifies 8 primary states organised into mutually antagonistic pairs. Each state has behavioural, learning and communication implications Plutchick’s model of emotion specifies 8 primary states organised into mutually antagonistic pairs. Each state has behavioural, learning and communication implications Embodied animats in games are a good test bed for emotions, because they can play out these implications in the game world, and should be more entertaining as a result Embodied animats in games are a good test bed for emotions, because they can play out these implications in the game world, and should be more entertaining as a result But the portrayal of emotions in games can be problematic, because the opportunities for facial expression, gestures etc. could be limited But the portrayal of emotions in games can be problematic, because the opportunities for facial expression, gestures etc. could be limited Champandard defines sensations, emotions, moods and feelings technically, as part of an application of Plutchick’s model to the design of a FEAR animat (Moody) Champandard defines sensations, emotions, moods and feelings technically, as part of an application of Plutchick’s model to the design of a FEAR animat (Moody) This model uses a FSA to transform perceptions into sensations This model uses a FSA to transform perceptions into sensations The sensations drive a FSM model of emotional states, each of which modifies the efficiency and speed of perceptions and actions in the Moody animat The sensations drive a FSM model of emotional states, each of which modifies the efficiency and speed of perceptions and actions in the Moody animat


Download ppt "Character Artificial Intelligence CE00875-3 Finite State Automata Finite State Automata Lecture 3."

Similar presentations


Ads by Google