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

Add BeliefVisualizer for belief evolution visualization and seaborn dependency #35

Merged
merged 3 commits into from
Nov 8, 2024

Conversation

leonvanbokhorst
Copy link
Owner

@leonvanbokhorst leonvanbokhorst commented Nov 8, 2024

  • Add seaborn to requirements.txt to include it as a dependency
  • Implement BeliefVisualizer class in belief_visualizer.py to create multi-panel visualizations of belief evolution
  • Update bayes_updating.py to import BeliefVisualizer and use it to plot belief evolution for a given topic

Summary by Sourcery

Introduce a new BeliefVisualizer class for visualizing belief evolution and update the Bayesian belief updating process to include visualization capabilities. Add seaborn as a dependency to support these visualizations.

New Features:

  • Implement the BeliefVisualizer class to create multi-panel visualizations of belief evolution.

Enhancements:

  • Update bayes_updating.py to integrate the BeliefVisualizer for plotting belief evolution.

Build:

  • Add seaborn to requirements.txt as a new dependency for visualization purposes.

- Add confidence dampening to prevent saturation at high values
- Implement time-based decay factor for long-term uncertainty
- Increase sensitivity to divergent evidence (threshold 0.7)
- Cap maximum confidence at 0.95
- Add confidence decay factor of 0.995 per update

System now shows more realistic belief evolution:
- Better handles contradictory evidence
- Maintains appropriate uncertainty
- Prevents overconfidence
- Shows natural confidence erosion over time

Testing shows smooth confidence transitions from 0.5→0.92→0.45
over 10 updates with mixed evidence.
- Add seaborn to requirements.txt to include it as a dependency
- Implement BeliefVisualizer class in belief_visualizer.py to create multi-panel visualizations of belief evolution
- Update bayes_updating.py to import BeliefVisualizer and use it to plot belief evolution for a given topic
Copy link
Contributor

sourcery-ai bot commented Nov 8, 2024

Reviewer's Guide by Sourcery

This PR implements a Bayesian belief updating system with visualization capabilities. The implementation includes a new BeliefVisualizer class for creating multi-panel visualizations of belief evolution over time, and updates to the Bayesian updating system to integrate with this visualization component. The system uses seaborn for enhanced plotting capabilities.

Sequence diagram for belief updating and visualization

sequenceDiagram
    actor User
    participant BayesianBeliefUpdater
    participant BeliefVisualizer
    User->>BayesianBeliefUpdater: initialize_belief_state(topic)
    BayesianBeliefUpdater->>BayesianBeliefUpdater: generate_embedding(topic)
    BayesianBeliefUpdater->>BayesianBeliefUpdater: create BeliefState
    User->>BayesianBeliefUpdater: update_belief(topic, new_evidence)
    BayesianBeliefUpdater->>BayesianBeliefUpdater: generate_embedding(new_evidence)
    BayesianBeliefUpdater->>BayesianBeliefUpdater: calculate likelihood
    BayesianBeliefUpdater->>BayesianBeliefUpdater: update belief vector
    User->>BayesianBeliefUpdater: analyze_belief_shift(topic)
    BayesianBeliefUpdater->>User: return analysis
    User->>BeliefVisualizer: plot_belief_evolution(analysis, evidence_list, topic)
    BeliefVisualizer->>BeliefVisualizer: create visualization
Loading

Class diagram for Bayesian belief updating system

classDiagram
    class BeliefState {
        np.ndarray belief_vector
        float confidence
        List~Tuple~np.ndarray, float~~ prior_states
        List~str~ themes
    }

    class BayesianBeliefUpdater {
        -LanguageModel llm
        -Dict~str, BeliefState~ belief_states
        -Dict theme_weights
        -Logger logger
        +initialize_belief_state(topic: str) BeliefState
        +update_belief(topic: str, new_evidence: str) BeliefState
        +analyze_belief_shift(topic: str) Dict
    }

    class BeliefVisualizer {
        -Path output_dir
        +plot_belief_evolution(analysis: Dict, evidence_list: List~str~, topic: str)
    }

    BayesianBeliefUpdater --> BeliefState
    BayesianBeliefUpdater --> BeliefVisualizer
Loading

File-Level Changes

Change Details Files
Implementation of Bayesian belief updating system with vector embeddings
  • Created BeliefState dataclass to store belief vectors, confidence, and history
  • Implemented BayesianBeliefUpdater class with initialization and update methods
  • Added Bayesian update algorithm using cosine similarity and confidence updating
  • Implemented belief shift analysis functionality
  • Added demonstration code in main() function
src/bayes_updating.py
Creation of visualization system for belief evolution
  • Implemented BeliefVisualizer class with configurable output directory
  • Added multi-panel visualization with belief shifts and confidence changes
  • Created clean, modern plotting style configuration
  • Added evidence annotation system for tracking belief changes
  • Implemented high-DPI figure export functionality
src/belief_visualizer.py
Added visualization dependency
  • Added seaborn package to requirements.txt
requirements.txt

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 changed the title Bayesian-updating @sourcery-ai Nov 8, 2024
@sourcery-ai sourcery-ai bot changed the title @sourcery-ai Add BeliefVisualizer for belief evolution visualization and seaborn dependency Nov 8, 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 error handling for file operations in BeliefVisualizer, particularly around directory creation and file saving. This would prevent silent failures due to permission issues.
Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

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 leonvanbokhorst self-assigned this Nov 8, 2024
@leonvanbokhorst leonvanbokhorst added documentation Improvements or additions to documentation enhancement New feature or request labels Nov 8, 2024
@leonvanbokhorst leonvanbokhorst added this to the Phase 1 milestone Nov 8, 2024
- Add adaptive B-spline interpolation based on available data points
- Implement fallback to direct line plotting for sparse data
- Fix matplotlib style configuration
- Ensure graceful handling of different data densities

The visualization now automatically adjusts its smoothing approach
based on the number of data points, preventing interpolation errors
while maintaining an aesthetically pleasing appearance.
@leonvanbokhorst leonvanbokhorst merged commit 9f1a54f into main Nov 8, 2024
1 check passed
@leonvanbokhorst leonvanbokhorst deleted the bayesian-updating branch November 8, 2024 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant