Skip to content

KLEPEmotion

Roll4d4 edited this page Feb 23, 2025 · 1 revision

๐Ÿง  KLEPEmotion: Modeling Emotional States in KLEP

The KLEPEmotion class is an experimental module in KLEP, designed to introduce emotional states to AI agents. It simulates emotions using vector mathematics, allowing agents to react dynamically based on their emotional history and current stimuli. This system aims to enhance agent behavior, enabling adaptive and nuanced responses.


๐Ÿšฆ What Does KLEPEmotion Do?

  1. Emotional State Management:

    • Tracks the agent's current emotional state as a Vector4.
    • Applies emotional inertia (smoothing transitions) and friction (emotional decay).
  2. Emotional History Tracking:

    • Stores past emotional states in a history buffer.
    • Limits history size to avoid memory bloat.
  3. Emotional Analysis:

    • Calculates overall emotional state by combining historical emotions.
    • Assesses emotional stability, potentially influencing agent decisions.
  4. Emotional Reactions:

    • Provides a framework for interpreting emotions and triggering behaviors.
    • Supports dynamic responses based on stability and emotional dominance.

๐Ÿ” Core Components of KLEPEmotion:


๐Ÿง  1. Emotional State & History

private List<Vector4> emotionalHistory = new List<Vector4>();
private const int EmotionalHistoryLimit = 10; // Limit the history to the last N emotions
private const float EmotionalFriction = 0.1f; // Rate at which emotions degrade over time
private const float EmotionalInertia = 0.8f; // Factor for considering past emotions

[SerializeField]
private Vector4 currentEmotionalState = new Vector4(0, 0, 0, 1); // Initial emotional state
  • Emotional State (Vector4):

    • Represents emotions as a 4D vector.
    • Components (x, y, z, w) can be mapped to specific emotions, such as:
      • x: Happiness (positive emotion).
      • y: Sadness (negative emotion).
      • z: Anger (reactive emotion).
      • w: Stability (resistance to change).
  • Emotional History (List<Vector4>):

    • Stores recent emotional states, allowing contextual behavior.
    • Limits history size to maintain performance.
  • Emotional Parameters:

    • Friction: Decreases intensity of emotions over time, mimicking emotional decay.
    • Inertia: Smooths transitions, preventing abrupt emotional changes.

๐Ÿ”„ 2. Emotional Inertia & Friction (ApplyEmotionalInertiaAndFriction)

private void ApplyEmotionalInertiaAndFriction(Vector4 newEmotion)
{
    // Apply inertia to smooth out the transition between emotions
    Vector4 inertiaAppliedEmotion = Vector4.Lerp(currentEmotionalState, newEmotion, EmotionalInertia);

    // Apply friction to reduce the emotional intensity over time
    currentEmotionalState = inertiaAppliedEmotion * (1 - EmotionalFriction);
}
  • Emotional Inertia:

    • Uses Vector4.Lerp to smoothly transition from the current state to the new emotion.
    • Helps avoid sudden shifts in emotional state.
  • Emotional Friction:

    • Dampens emotional intensity by scaling down the vector.
    • Simulates emotional cooling, preventing runaway states.

๐Ÿ’ก 3. Updating Emotional History (UpdateEmotionalHistory)

private void UpdateEmotionalHistory(Vector4 currentEmotion)
{
    emotionalHistory.Add(currentEmotion);
    if (emotionalHistory.Count > EmotionalHistoryLimit)
    {
        emotionalHistory.RemoveAt(0); // Remove oldest emotion
    }
}
  • Adds the current emotion to the history buffer.
  • Automatically prunes old entries to maintain a fixed size.
  • Supports trend analysis, such as detecting rising frustration or prolonged joy.

๐Ÿง  4. Calculating Overall Emotional State (CalculateOverallEmotionalState)

private Vector4 CalculateOverallEmotionalState()
{
    Vector4 combinedEmotion = new Vector4(0, 0, 0, 0);
    foreach (var emotion in emotionalHistory)
    {
        combinedEmotion += emotion;
    }
    return combinedEmotion.normalized; // Normalize to maintain consistent scale
}
  • Combines historical emotions to produce a general state.
  • Normalizes the result, ensuring consistent intensity regardless of history size.
  • Useful for long-term behavioral influences, such as character mood.

๐Ÿง  5. Evaluating Emotional Stability (CalculateEmotionalStability)

private float CalculateEmotionalStability(Vector4 emotionalState)
{
    return emotionalState.w; // Using the 4th dimension (w) as a measure of stability
}
  • Uses the 4th dimension (w) of the emotional vector to represent stability.
  • Higher stability values indicate resilience to emotional shifts.
  • Low stability may trigger specific behaviors, such as seeking comfort or avoiding danger.

๐Ÿ’ก EmotionalImpact Class: Reactions & Interpretation

public class EmotionalImpact
{
    public Vector4 CurrentEmotion { get; set; }
    public Vector4 OverallEmotionalState { get; set; }
    public float EmotionalStability { get; set; }

    public string InterpretEmotionalState()
    {
        if (EmotionalStability < 0.2f)
        {
            return "Highly unstable emotional state";
        }
        else if (OverallEmotionalState.x > 0.5f)
        {
            return "Predominantly positive emotions";
        }
        else if (OverallEmotionalState.y > 0.5f)
        {
            return "Predominantly negative emotions";
        }
        return "Neutral or mixed emotions";
    }

    public void ReactToEmotionalState()
    {
        if (EmotionalStability < 0.2f)
        {
            // Behavior for stabilizing emotions
        }
        else if (OverallEmotionalState.x > 0.5f)
        {
            // Behavior for reinforcing positive emotions
        }
        else if (OverallEmotionalState.y > 0.5f)
        {
            // Behavior for mitigating negative emotions
        }
        else
        {
            // Behavior for neutral or mixed emotional states
        }
    }
}

๐Ÿง  Key Features:

  • Interprets current emotions, providing human-readable feedback.
  • Triggers specific behaviors based on emotional stability and dominant emotions.
  • Supports adaptive AI, allowing agents to respond naturally to prolonged stimuli.

๐ŸŽฎ Example Scenario: Emotional AI in a Game:

๐Ÿค– Scenario: A Companion Robot's Emotional Responses:

  1. The robot experiences positive emotions when praised, updating its current emotional state.
  2. Emotional inertia ensures the robot remains in a good mood for a prolonged period.
  3. If the robot is ignored, emotional friction dampens positivity, shifting it to a neutral state.
  4. If negative events occur repeatedly, the robot's stability may decrease, leading to cautionary behaviors.

โœ… Key Takeaways:

  • KLEPEmotion introduces emotional intelligence to AI agents, enabling dynamic behavior.
  • Combines historical data with current stimuli to produce authentic responses.
  • Supports advanced behavior systems, such as adaptive dialogue, mood-driven actions, and contextual decision-making.
  • This is an experimental feature, but demonstrates the potential of combining symbolic AI with emotional models.

Would you like further development on how to integrate emotional states with goals, actions, or Q-learning in KLEP? ๐Ÿ˜Š

KLEP Wiki Navigation

๐Ÿš€ Getting Started

๐Ÿง  Core Concepts

๐ŸŽฎ Examples and Tutorials

๐Ÿ› ๏ธ Scripts and Components

๐Ÿ’ก Experimental/Project Projections

๐Ÿงฌ Contributing

Clone this wiki locally