viva_emotion/mood
Mood - Long-term emotional state via Exponential Moving Average
Theory
Mood differs from emotion:
| Aspect | Emotion | Mood |
|---|---|---|
| Duration | Seconds-minutes | Hours-days |
| Trigger | Specific event | Accumulated state |
| Intensity | High variance | Low variance |
Implementation
Exponential Moving Average (EMA):
Mood[t] = α × Emotion[t] + (1 - α) × Mood[t-1]
Where α (smoothing factor) controls responsiveness:
- α = 0.05 → Very stable mood (~20 step half-life)
- α = 0.10 → Moderate responsiveness (~10 step half-life)
- α = 0.20 → Quick mood shifts (~5 step half-life)
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
- Davidson (1994). On Emotion, Mood, and Related Affective Constructs.
- Watson & Tellegen (1985). Psychological Bulletin, 98, 219-235.
Types
Values
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 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 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