This example walks through a simulation showing how mood changes after significant life events. We will create an entity, establish their baseline emotional state, apply negative and positive events, and observe how mood declines and recovers over time through the decay mechanism.
The Scenario
We model someone named Maya who experiences social exclusion (being left out of an important group activity) on Day 10, and then social inclusion (being welcomed into a new group) on Day 20. We will query her mood at various timepoints to observe the emotional trajectory.
Step 1: Create the Entity
First, we create Maya with her personality traits. Her emotionality level will influence how strongly she reacts to social events.
// Create Maya with moderate emotionality
let maya = EntityBuilder::new("maya", Species::Human)
.with_age(27)
.with_hexaco(Hexaco {
honesty_humility: 0.6,
emotionality: 0.6, // Moderately emotionally reactive
extraversion: 0.7, // Socially oriented - social events matter more
agreeableness: 0.65,
conscientiousness: 0.5,
openness: 0.6,
})
.build();
// Add to simulation with anchor timestamp
let mut sim = Simulation::new();
let day_0 = Timestamp::from_date(2024, 1, 1);
sim.add_entity(maya, day_0);
Step 2: Establish Baseline Mood
Maya's mood is represented in PAD space (Pleasure, Arousal, Dominance). Let us query her baseline state before any events occur.
// Query baseline mood at Day 5 (before any events)
let maya_handle = sim.query_entity("maya");
let day_5 = Timestamp::from_date(2024, 1, 6);
let baseline_mood = maya_handle.mood_at(day_5);
println!("Maya's baseline mood (Day 5):");
println!(" Pleasure: {:.2}", baseline_mood.pleasure); // 0.15 (slightly positive)
println!(" Arousal: {:.2}", baseline_mood.arousal); // 0.10 (calm)
println!(" Dominance: {:.2}", baseline_mood.dominance); // 0.20 (moderate control)
Maya's baseline reflects a generally positive, calm state. This is computed from her personality: her extraversion contributes to positive baseline valence, and her moderate emotionality means she is neither particularly anxious nor unusually calm.
Step 3: Apply the Negative Event
On Day 10, Maya experiences social exclusion. Her work team goes to lunch without inviting her, which she interprets as deliberate exclusion.
// Social exclusion event on Day 10
let exclusion_event = EventBuilder::new(EventType::SocialExclusion)
.with_target("maya")
.with_severity(0.5) // Moderate severity
.with_context(Context::Work)
.with_perceived_intentionality(0.7) // She thinks it was deliberate
.build();
let day_10 = Timestamp::from_date(2024, 1, 11);
sim.add_event(exclusion_event, day_10);
Step 4: Query Mood After Exclusion
Now we query Maya's mood at several timepoints after the exclusion event to observe the impact and decay.
// Query mood immediately after (Day 11)
let day_11 = Timestamp::from_date(2024, 1, 12);
let mood_day_11 = maya_handle.mood_at(day_11);
println!("Maya's mood (Day 11, immediately after exclusion):");
println!(" Pleasure: {:.2}", mood_day_11.pleasure); // -0.25 (negative)
println!(" Arousal: {:.2}", mood_day_11.arousal); // 0.35 (elevated stress)
println!(" Dominance: {:.2}", mood_day_11.dominance); // -0.05 (feeling powerless)
// Query mood at Day 15 (5 days after, partial recovery)
let day_15 = Timestamp::from_date(2024, 1, 16);
let mood_day_15 = maya_handle.mood_at(day_15);
println!("Maya's mood (Day 15, partial recovery):");
println!(" Pleasure: {:.2}", mood_day_15.pleasure); // -0.05 (almost neutral)
println!(" Arousal: {:.2}", mood_day_15.arousal); // 0.18 (calming down)
println!(" Dominance: {:.2}", mood_day_15.dominance); // 0.10 (regaining sense of control)
Understanding the Decay
The mood delta from the exclusion event decays exponentially over time. With a typical mood half-life of 3-4 days:
- Day 11: Full impact of the negative delta
- Day 15: Delta has decayed to roughly 25% of its original value
- Maya is approaching her baseline, though not fully recovered
Step 5: Apply the Positive Event
On Day 20, Maya joins a new hobby group and experiences social inclusion - being warmly welcomed and immediately included in group activities.
// Social inclusion event on Day 20
let inclusion_event = EventBuilder::new(EventType::SocialInclusion)
.with_target("maya")
.with_severity(0.6) // Moderately positive
.with_context(Context::Social)
.with_warmth(0.8) // Very welcoming atmosphere
.build();
let day_20 = Timestamp::from_date(2024, 1, 21);
sim.add_event(inclusion_event, day_20);
Step 6: Query the Full Trajectory
Now we can query mood at multiple timepoints to see the complete emotional journey.
// Query comprehensive timeline
let timepoints = vec![
("Day 5 (baseline)", Timestamp::from_date(2024, 1, 6)),
("Day 11 (post-exclusion)", Timestamp::from_date(2024, 1, 12)),
("Day 15 (recovering)", Timestamp::from_date(2024, 1, 16)),
("Day 19 (pre-inclusion)", Timestamp::from_date(2024, 1, 20)),
("Day 21 (post-inclusion)", Timestamp::from_date(2024, 1, 22)),
("Day 30 (stabilized)", Timestamp::from_date(2024, 1, 31)),
];
println!("Maya's Emotional Journey:");
println!("----------------------------------------");
for (label, timestamp) in timepoints {
let mood = maya_handle.mood_at(timestamp);
println!("{}", label);
println!(" Pleasure: {:+.2}", mood.pleasure);
println!("");
}
// Output:
// Day 5 (baseline): Pleasure: +0.15
// Day 11 (post-exclusion): Pleasure: -0.25
// Day 15 (recovering): Pleasure: -0.05
// Day 19 (pre-inclusion): Pleasure: +0.12 (nearly back to baseline)
// Day 21 (post-inclusion): Pleasure: +0.45 (boosted by inclusion)
// Day 30 (stabilized): Pleasure: +0.22 (settling above original baseline)
Visualizing the Trajectory
If we plot Maya's pleasure dimension over time, we see:
The Emotional Curve
Days 1-9: Stable at baseline (+0.15)
Day 10: Sharp drop from exclusion event
Days 11-19: Exponential recovery toward baseline
Day 20: Sharp rise from inclusion event
Days 21-30: Decay back toward (slightly elevated) baseline
The final state (+0.22) is above the original baseline (+0.15). This is because the positive inclusion event occurred while there was still a small residual negative delta from exclusion. The two deltas interact: the remaining negative delta gets partially offset, and the new positive delta adds on top.
The Role of Personality
Maya's personality affects her emotional trajectory in several ways:
// Compare with a less emotionally reactive person
let calm_person = EntityBuilder::new("alex", Species::Human)
.with_hexaco(Hexaco {
emotionality: 0.3, // Low emotional reactivity
extraversion: 0.4, // Less socially oriented
// ... other traits
})
.build();
// Same events produce smaller deltas for Alex
// Exclusion might only drop pleasure to -0.10 instead of -0.25
// Recovery is faster because delta is smaller
// The same events matter less to someone less emotionally reactive
Personality as Interpretation Filter
The events themselves are the same. The difference is in interpretation:
- High emotionality: Events create larger deltas, more dramatic swings
- High extraversion: Social events carry more weight than for introverts
- Low emotionality: Same events create smaller deltas, faster return to baseline
Temporal Queries: Any Direction
One powerful feature is that we can query in any temporal direction - past, present, or projected future.
// Query what mood WILL BE at Day 45, assuming no new events
let day_45 = Timestamp::from_date(2024, 2, 15);
let projected_mood = maya_handle.mood_at(day_45);
println!("Projected mood at Day 45: {:.2}", projected_mood.pleasure); // ~0.16
// The positive delta from inclusion has mostly decayed
// Maya returns close to her original baseline
// No stored history needed - computed from events and decay
What This Example Demonstrates
Events Create Deltas
Life events do not set mood directly - they create deviations from baseline that decay over time.
Decay Models Recovery
The exponential decay mechanism captures how emotional responses fade. Sharp pain becomes dull; euphoria settles into contentment.
Personality Shapes Response
The same event produces different impacts depending on personality. Emotionality, extraversion, and other traits filter how events are processed.
Temporal Queryability
State at any time is computed on demand. Query the past, present, or projected future without storing snapshots.
Try It Yourself
Experiment with different scenarios:
- What if the exclusion event was more severe (0.8 instead of 0.5)?
- What if Maya had lower extraversion and did not care as much about social events?
- What happens with repeated exclusion events - do the deltas compound?
- At what point would a severe event cross the formative threshold and shift baseline?
For more details on the StateValue abstraction and decay mechanics, see Understanding State.