Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PoC Three evolving stories #19

Merged
merged 16 commits into from
Oct 26, 2024
Merged

PoC Three evolving stories #19

merged 16 commits into from
Oct 26, 2024

Conversation

leonvanbokhorst
Copy link
Owner

@leonvanbokhorst leonvanbokhorst commented Oct 26, 2024

Summary by Sourcery

Introduce a new module for simulating evolving stories within a narrative field, enhancing configuration settings for performance, and adding documentation to narrate the conceptual story of these interactions.

New Features:

  • Introduce a new module 'nfd_three_story_evolve.py' that simulates the interaction of stories within a narrative field, focusing on themes, emotional states, and story evolution.
  • Add a new markdown documentation file 'nfd_three_story_evolve.md' that narrates the conceptual story of three evolving narratives within a field.

Enhancements:

  • Increase the 'n_ctx' parameter from 4096 to 16384 and 'n_threads' from 4 to 8 in the optimal configuration settings to enhance performance.

Documentation:

  • Add 'nfd_three_story_evolve.md' to document the narrative and interactions of three evolving stories in a narrative field.

The simulation framework aligns well with the intended narrative dynamics:

Resonance and Theme Influence: The system effectively uses resonance and thematic influence to determine the strength and direction of interactions between stories, as seen in the ThemeRelationshipMap and update_perspective methods.
Perspective Shifts: The StoryPerspective and Story classes handle perspective shifts, allowing stories to evolve in response to interactions without losing their core identity. This mirrors the idea of stories subtly adapting with each experience.
Memory Formation: Each story’s memory_layer and resonance_history capture cumulative experiences, which can impact future interactions and perspective adjustments.
The emotional changes are now visible and vary between interactions. For example:
00
This shows that the stories are experiencing emotional changes during interactions.
Varied Emotional Impacts:
Different interactions result in different emotional impacts. For instance:
04
This indicates that stories are responding differently to interactions based on their themes and resonance.
Resonance Levels:
The resonance levels between stories vary (e.g., 0.36, 0.39, 0.38), which affects the strength of their interactions and emotional impacts.
4. Theme Relationships:
The simulation is identifying theme relationships between stories, such as:
]
These relationships contribute to the emotional and thematic interactions between stories.
5. Memory Formation:
Stories are forming memories of their interactions, including the themes they gain from other stories.
The stories are consistently interacting with each other, as evidenced by the numerous memory formations and emotional updates.
Resonance levels between stories range from about 0.26 to 0.28, indicating moderate levels of connection.
There are no directly shared themes between the stories, but they influence each other through related themes (e.g., "loneliness" and "discovery", "guidance" and "nature").
Emotional Impact:
Each interaction causes subtle changes in the emotional states of the stories.
All stories seem to maintain high levels of joy, hope, and curiosity throughout the interactions.
Fear and sadness fluctuate more, sometimes increasing slightly after interactions.
3. Perspective Shifts:
The stories experience small but consistent perspective shifts with each interaction.
The dream story seems to have undergone the largest total perspective shift (22.7162), followed by the lighthouse (11.8148), and then the path (6.7595).
Movement Patterns:
All three stories have traveled significant distances (260+ units) but ended up relatively close to their starting positions (direct distances of 1.77 to 2.35 units).
This results in high "wandering ratios" (111 to 148), indicating complex, non-linear paths through the narrative space.
Memory Formation:
Each story formed 20,000 memories, suggesting frequent and consistent interactions.
Interestingly, they each only record 2 unique interactions, which might indicate a focus on deeper, repeated engagements with the same stories.
6. Theme Dynamics:
While there are no directly shared themes, the stories are influencing each other's thematic content through related concepts.
The theme relationships (e.g., "duty" and "freedom", "guidance" and "imagination") suggest a rich interplay of ideas.
7. Collective Behavior:
The consistent interaction patterns and similar movement metrics suggest a kind of collective behavior emerging from the individual story dynamics.
These results demonstrate a complex, interconnected narrative ecosystem where stories influence each other in subtle but significant ways. The high wandering ratios and large total distances traveled suggest a rich exploration of the narrative space, while the emotional and thematic interactions show how the stories are constantly evolving in response to each other.
- Implement more nuanced interaction types (collaboration, conflict, inspiration, reflection)
- Add emotional state tracking and updates for stories
- Improve theme evolution and perspective shift mechanics
- Enhance StoryPhysics with balanced forces and exploration
- Implement StoryJourneyLogger for detailed interaction and movement tracking
- Add EnhancedCollectiveStoryEngine for emergent theme detection
- Refine resonance calculation with emotional similarity
- Implement memory formation with emotional impact
- Add periodic field pulses to simulate collective events
- Enhance visualization capabilities for field state capture
1. Story Generation and Interaction:
The simulation created 4 stories (story_0 to story_3).
Each story interacted with the other 3 stories, as evidenced by the "Unique Interactions: 3" metric for all stories.
Movement and Trajectories:
All stories showed significant movement, with total distances traveled ranging from 1.48 to 2.27 units.
The stories exhibited complex trajectories, as indicated by the high "Wandering Ratio" values (ranging from 2.41 to 7.30). This suggests that the stories took indirect paths rather than moving in straight lines.
Story_0 had the highest wandering ratio (7.30), indicating it had the most complex trajectory.
Interactions and Memories:
The stories formed a varying number of memories, ranging from 120 (story_1) to 301 (story_3).
The high number of memories compared to unique interactions suggests that stories had multiple interactions with each other.

Perspective Shifts:
All stories underwent significant total perspective shifts, ranging from 15.4215 (story_1) to 79.0313 (story_3).
Interestingly, the average shift magnitude and significant perspective changes are reported as 0 for all stories. This could indicate that while many small shifts occurred, they didn't meet the threshold for "significant" changes.
Final Positions and Velocities:
The stories ended up in different quadrants of the 3D space, suggesting they diverged over time.
Final velocities are relatively small compared to the total distances traveled, indicating that the stories' movements slowed down towards the end of the simulation.
6. Story-Specific Observations:
Story_0: Traveled the second-longest distance but ended up closest to its starting point, hence its high wandering ratio.
Story_1: Had the fewest memories but traveled the longest distance.
Story_2: Showed balanced behavior in terms of distance traveled and memories formed.
Story_3: Formed the most memories and underwent the largest perspective shift, despite traveling the shortest distance.
7. Simulation Dynamics:
The varying number of memories and perspective shifts for each story suggests that the stories had different levels of susceptibility to interactions and environmental influences.
The high number of significant events (equal to the number of memories for each story) indicates that the simulation captured many noteworthy moments in the stories' journeys.
Overall, the simulation demonstrates complex dynamics with stories showing individual behaviors while still influencing each other. The high wandering ratios and the discrepancy between total distance traveled and direct distance suggest that the narrative field effectively created intricate paths for the stories, mimicking the complex nature of narrative evolution.
- Update EmotionalState to use embeddings instead of discrete emotions
- Modify Story class to handle asynchronous updates and interactions
- Enhance EnhancedInteractionEngine for more nuanced story interactions
- Update DynamicStoryGenerator to create more detailed stories with protagonists
- Improve EnvironmentalEventGenerator for positive/negative events
- Refactor StoryJourneyLogger and add new JourneyLogger for better logging
- Update simulate_field function to handle asynchronous operations and improved logging
- Various code cleanup and optimization throughout the simulation
Copy link
Contributor

sourcery-ai bot commented Oct 26, 2024

Reviewer's Guide by Sourcery

This PR introduces a sophisticated narrative field simulation system that models interactions between stories in a virtual space. The implementation uses advanced concepts like embeddings, emotional states, and physics-based interactions to create dynamic story evolution. The system includes multiple components for handling story generation, interactions, physics, logging, and visualization.

Sequence diagram for story interaction processing

sequenceDiagram
    participant Story1
    participant Story2
    participant InteractionEngine
    participant Field
    participant LLM as LanguageModel

    Story1->>InteractionEngine: process_interaction(Story2)
    InteractionEngine->>Field: detect_resonance(Story1, Story2)
    Field-->>InteractionEngine: resonance
    InteractionEngine->>Story1: update_perspective(Story2, theme_impact, resonance, emotional_change, interaction_type)
    InteractionEngine->>Story1: update_emotional_state(Story2, interaction_type, resonance, LLM)
    Story1->>Story1: Add memory of interaction
    InteractionEngine-->>Story1: return resonance, interaction_type
Loading

Architecture diagram for the narrative field simulation system

graph TD;
    subgraph SimulationComponents
        StoryGenerator
        ThemeGenerator
        EventGenerator
        InteractionEngine
        Physics
        Visualizer
        CollectiveEngine
    end
    subgraph NarrativeField
        Story
        FieldMemory
        CollectiveState
    end
    subgraph Logging
        JourneyLogger
        StoryJourneyLogger
    end
    StoryGenerator -->|generates| Story
    ThemeGenerator -->|provides themes to| StoryGenerator
    EventGenerator -->|generates events for| NarrativeField
    InteractionEngine -->|processes interactions in| NarrativeField
    Physics -->|updates motion of| Story
    Visualizer -->|captures state of| NarrativeField
    CollectiveEngine -->|updates story states in| NarrativeField
    JourneyLogger -->|logs journey of| Story
    StoryJourneyLogger -->|logs detailed journey of| Story
    Story -->|interacts with| Story
    Story -->|has| EmotionalState
    Story -->|exists in| NarrativeField
    NarrativeField -->|contains| Story
    NarrativeField -->|has| FieldMemory
    NarrativeField -->|has| CollectiveState
    CollectiveEngine -->|detects emergent themes in| NarrativeField
    CollectiveEngine -->|writes collective story for| NarrativeField
    InteractionEngine -->|uses| LLM[LanguageModel]
Loading

Class diagram for the new narrative field simulation system

classDiagram
    class Story {
        +String id
        +String content
        +np.ndarray embedding
        +np.ndarray perspective_filter
        +List~String~ themes
        +NarrativeField field
        +np.ndarray position
        +np.ndarray velocity
        +EmotionalState emotional_state
        +String protagonist_name
        +async update_perspective(other_story, theme_impact, resonance, emotional_change, interaction_type)
        +async update_emotional_state(other, interaction_type, resonance, llm)
        +async respond_to_environmental_event(event)
        +async update_state(avg_resonance, avg_shift)
    }

    class EmotionalState {
        +String description
        +np.ndarray embedding
        +async update(other, interaction_strength, llm)
    }

    class NarrativeField {
        +int dimension
        +List~Story~ stories
        +np.ndarray collective_state
        +float time
        +detect_resonance(story1, story2)
        +add_story(story)
        +async apply_environmental_event(event)
    }

    class StoryPhysics {
        +float damping
        +float attraction_strength
        +float max_force
        +float max_velocity
        +update_story_motion(story, field, timestep)
    }

    class EnhancedInteractionEngine {
        +NarrativeField field
        +LanguageModel llm
        +async process_interaction(story1, story2)
        +calculate_theme_impact(story1, story2)
    }

    Story --> EmotionalState
    Story --> NarrativeField
    EnhancedInteractionEngine --> NarrativeField
    EnhancedInteractionEngine --> Story
    StoryPhysics --> Story
    StoryPhysics --> NarrativeField
Loading

File-Level Changes

Change Details Files
Implemented a new narrative field simulation system
  • Created core Story class with position, velocity, emotional state, and theme tracking
  • Implemented physics engine for story movement and interactions
  • Added emotional state handling with LLM integration
  • Created logging system for tracking story journeys and interactions
  • Implemented theme relationship and evolution system
src/nfd_three_story_evolve.py
Added documentation for the three-story narrative field concept
  • Documented the concept of three interacting stories in the field
  • Described story interactions and collective memory formation
  • Explained the technical implementation of story resonance and memory
src/nfd_three_story_evolve.md
Updated model configuration parameters
  • Increased context window size from 4096 to 16384
  • Doubled number of processing threads from 4 to 8
src/config.py
Modified issue template configuration
  • Added project field with 'friction-flow' value
.github/ISSUE_TEMPLATE/issue-.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@leonvanbokhorst leonvanbokhorst self-assigned this Oct 26, 2024
@leonvanbokhorst leonvanbokhorst added the enhancement New feature or request label Oct 26, 2024
@leonvanbokhorst leonvanbokhorst added this to the Phase 1 milestone Oct 26, 2024
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @leonvanbokhorst - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding unit tests for the core components (Story, NarrativeField, StoryPhysics) to ensure behavior remains consistent as the system evolves.
  • There may be opportunities for performance optimization in the physics calculations, particularly in the force computations between stories. Consider vectorizing these operations in a future update.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟡 Documentation: 2 issues found

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

leonvanbokhorst and others added 4 commits October 26, 2024 15:06
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
@leonvanbokhorst leonvanbokhorst merged commit 35bb098 into main Oct 26, 2024
1 check passed
@leonvanbokhorst leonvanbokhorst deleted the dev branch October 26, 2024 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant