BayesCalc2¶
A powerful Bayesian network calculator with interactive REPL
BayesCalc2 is a command-line tool for defining, analyzing, and querying Bayesian networks. It provides an intuitive syntax for specifying probabilistic relationships and a rich set of commands for probability inference.
Features¶
- 🔢 Bayesian Network Definition: Simple, human-readable
.netfile format - 🧮 Probability Queries: Natural syntax like
P(Rain|GrassWet) - 📊 Network Visualization: Generate PDF diagrams of your networks
- 🔍 Advanced Inference: Variable elimination algorithm for efficient computation
- 💻 Interactive REPL: Tab completion, command history, and helpful feedback
- 📝 Batch Processing: Run multiple commands from script files
- 🔗 Boolean Shorthand: Concise syntax for binary variables (
RainvsRain=True)
Quick Start¶
Installation¶
Or install from source:
Your First Network¶
Create a simple network file rain.net:
variable Rain {True, False}
variable Sprinkler {On, Off}
variable GrassWet {Yes, No}
Rain { P(True) = 0.2 }
Sprinkler { P(On) = 0.1 }
GrassWet | Rain, Sprinkler {
P(Yes | True, On) = 0.99
P(Yes | True, Off) = 0.90
P(Yes | False, On) = 0.85
P(Yes | False, Off) = 0.05
}
Run Interactive Mode¶
Then query probabilities:
Batch Mode¶
Create a command file queries.txt:
Run it:
Documentation¶
- User Guide: Complete guide to using BayesCalc2
- Developer Guide: Architecture and development workflows
- Examples: Sample networks and use cases
- API Reference: Detailed API documentation
Example Networks¶
BayesCalc2 includes several example networks:
- Medical Diagnosis: Disease testing with false positives/negatives
- Weather Prediction: Rain, sprinkler, and grass wetness
- Student Performance: Exam results based on intelligence and difficulty
- Asia Chest Clinic: Medical diagnosis network from literature
- Monty Hall Problem: Classic probability puzzle
See the Examples page for detailed explanations.
Architecture¶
BayesCalc2 uses a pipeline architecture:
Key components:
- Lexer: Tokenizes
.netfiles - Parser: Builds abstract syntax tree and network model
- BayesianNetwork: Data model for variables, domains, and CPTs
- Inference: Variable elimination algorithm for probability computation
- REPL: Interactive shell with tab completion
Contributing¶
Contributions are welcome! Please see the Developer Guide for:
- Setting up the development environment
- Running tests
- Code style guidelines
- Architecture overview
License¶
BayesCalc2 is released under the MIT License. See LICENSE for details.