viva_emotion/mood

Mood - Long-term emotional state via Exponential Moving Average

Theory

Mood differs from emotion:

AspectEmotionMood
DurationSeconds-minutesHours-days
TriggerSpecific eventAccumulated state
IntensityHigh varianceLow variance

Implementation

Exponential Moving Average (EMA):

Mood[t] = α × Emotion[t] + (1 - α) × Mood[t-1]

Where α (smoothing factor) controls responsiveness:

Half-life formula: n = ln(0.5) / ln(1 - α)

Big Bounce Continuity

Mood carries across death/rebirth with decay:

Mood_new_life = decay_factor × Mood_at_death

This provides emotional continuity while allowing fresh starts.

References

Types

Mood state with configuration

pub type Mood {
  Mood(state: pad.Pad, alpha: Float, updates: Int)
}

Constructors

  • Mood(state: pad.Pad, alpha: Float, updates: Int)

    Arguments

    state

    Current mood (EMA of emotions)

    alpha

    Smoothing factor (lower = more stable)

    updates

    Number of updates (for statistics)

Values

pub fn activation(mood: Mood) -> Float

Get mood activation (arousal component)

pub fn blend(mood_a: Mood, mood_b: Mood, weight_a: Float) -> Mood

Blend two moods (for dream consolidation or parallel states)

pub fn bounce(mood: Mood, decay_factor: Float) -> Mood

Apply Big Bounce decay - mood partially carries to next life

decay_factor controls how much emotional continuity:

  • 0.8 = 80% mood survives (significant continuity)
  • 0.5 = 50% mood survives (moderate continuity)
  • 0.0 = Fresh start (no continuity)
pub const default_alpha: Float

Default smoothing factor (very stable mood) Half-life ≈ 14 updates: ln(0.5) / ln(0.95) ≈ 13.5

pub const default_bounce_decay: Float

Default bounce decay (80% survival)

pub fn get_state(mood: Mood) -> pad.Pad

Get current mood state

pub fn half_life(alpha: Float) -> Float

Calculate half-life in update steps Half-life = ln(0.5) / ln(1 - alpha) Uses precomputed ln(0.5) = -0.693147

pub fn is_negative(mood: Mood) -> Bool

Check if mood is negative (pleasure < threshold)

pub fn is_positive(mood: Mood) -> Bool

Check if mood is positive (pleasure > threshold)

pub fn is_stable(mood: Mood, baseline: pad.Pad) -> Bool

Check if mood is stable (low variance from neutral)

pub fn is_volatile(mood: Mood) -> Bool

Check if mood is volatile (high arousal component)

pub fn neutral() -> Mood

Create neutral mood

pub fn new(initial: pad.Pad) -> Mood

Create a new mood from initial state

pub fn new_with_alpha(initial: pad.Pad, alpha: Float) -> Mood

Create mood with custom smoothing factor

pub const quick_alpha: Float

Quick mood (more responsive to emotions) Half-life ≈ 7 updates

pub fn stability(mood: Mood, baseline: pad.Pad) -> Float

Calculate mood stability (inverse of recent change magnitude) Requires tracking previous state - returns distance from baseline

pub const traumatic_bounce_decay: Float

Traumatic bounce (50% survival - death was hard)

pub fn update(mood: Mood, emotion: pad.Pad) -> Mood

Update mood with new emotion observation

Uses EMA formula: Mood[t] = α × Emotion[t] + (1 - α) × Mood[t-1]

pub fn update_with_alpha(
  mood: Mood,
  emotion: pad.Pad,
  alpha: Float,
) -> Mood

Update with custom alpha (temporary override)

pub fn valence(mood: Mood) -> Float

Get mood valence (simplified pleasure-dominance combination)

pub const volatile_alpha: Float

Volatile mood (very responsive) Half-life ≈ 3 updates

Search Document