fugue-ppl 0.2.2

Monadic PPL with numerically stable inference and comprehensive diagnostics.
Documentation
# Contributing to Fugue

Thank you for your interest in contributing to Fugue! This document provides guidelines for contributing to the project.

## Community

- **Discord**: Join our [Discord server]https://discord.gg/QAcF7Nwr
- **Issues & Bugs**: Open an [issue]https://github.com/alexnodeland/fugue/issues with the `Bug Report` template.
- **Feature Requests**: Open an [issue]https://github.com/alexnodeland/fugue/issues with the `Feature Request` template.
- **RFCs**: Open an [issue]https://github.com/alexnodeland/fugue/issues with the `RFC` template.
- **Zotero**: Joing our [Zotero group]https://www.zotero.org/groups/6138134/fugue

## Quick Start

```bash
git clone https://github.com/alexnodeland/fugue.git
cd fugue
cargo test --all-features
```

## Development Setup

### Prerequisites

- Rust 1.70+ (install via [rustup]https://rustup.rs/)
- Git

### Building and Testing

```bash
# Run all tests
make test

# Format code
make fmt

# Lint code  
make lint

# Run benchmarks
make bench

# Generate coverage report
make coverage

# Run all checks
make all
```

Or use cargo directly:

```bash
cargo test --all-features
cargo fmt
cargo clippy -- -D warnings
```

## Contributing Guidelines

### Issues

- Use GitHub Issues for bug reports and feature requests
- Provide clear reproduction steps for bugs
- Include relevant code examples

### Pull Requests

- Fork the repository and create a short-lived feature branch from `main` (trunk-based development)
- **Rebase your branch** to the top of `main` before submitting PR
- Use **semantic commit messages** (e.g., `feat:`, `fix:`, `docs:`, `refactor:`)
- Add tests for new functionality
- **Ensure all CI checks pass** before requesting review
- PRs are **squash merged** to maintain linear history
- Update documentation as needed

### Versioning

- We follow [Semantic Versioning]https://semver.org/ (SemVer)
- Breaking changes increment major version
- New features increment minor version  
- Bug fixes increment patch version

### Code Style

- Follow Rust standard formatting (`cargo fmt`)
- Address all clippy warnings (`cargo clippy -- -D warnings`)
- Add documentation for public APIs
- Include examples in documentation

## Project Structure

```mermaid
graph LR
    A["๐ŸŽป Fugue<br/>Monadic Probabilistic Programming"] --> B["๐Ÿ“ฆ Core Module"]
    A --> C["๐Ÿ”ฌ Inference Module"]
    A --> D["โš™๏ธ Runtime Module"]
    A --> E["๐ŸŽ›๏ธ Macros Module"]
    A --> F["โš ๏ธ Error Module"]

    B --> B1["๐Ÿ“ Address System<br/>addr!(), scoped_addr!()"]
    B --> B2["๐Ÿ“Š Distributions<br/>10 type-safe distributions"]
    B --> B3["๐Ÿงฉ Model<T><br/>Monadic composition"]
    B --> B4["๐Ÿ”ข Numerical<br/>Stable algorithms"]

    B2 --> B2A["bool: Bernoulli"]
    B2 --> B2B["u64: Poisson, Binomial"]
    B2 --> B2C["usize: Categorical"]
    B2 --> B2D["f64: Normal, Beta, Gamma, etc."]

    C --> C1["๐Ÿ”— MCMC<br/>Adaptive Metropolis-Hastings"]
    C --> C2["๐ŸŽฏ SMC<br/>Particle filtering"]
    C --> C3["๐Ÿ“ˆ VI<br/>Mean-field approximation"]
    C --> C4["๐ŸŽฒ ABC<br/>Likelihood-free inference"]
    C --> C5["๐Ÿ“Š Diagnostics<br/>R-hat, ESS, validation"]

    D --> D1["๐ŸŽญ Handler System<br/>Effect interpreters"]
    D --> D2["๐Ÿ“ Trace System<br/>Execution history"]
    D --> D3["๐Ÿ’พ Memory Optimization<br/>Pooling & COW"]

    D1 --> D1A["PriorHandler"]
    D1 --> D1B["ReplayHandler"]
    D1 --> D1C["ScoreGivenTrace"]
    D1 --> D1D["Safe variants"]

    E --> E1["prob!<br/>Do-notation"]
    E --> E2["plate!<br/>Vectorization"]

    F --> F1["FugueError<br/>Rich error context"]

    G["๐Ÿ“š Documentation"] --> G1["User Guide<br/>20+ pages"]
    G --> G2["API Reference<br/>Complete rustdoc"]
    G --> G3["14 Examples<br/>Real-world scenarios"]

    H["๐Ÿงช Testing"] --> H1["82+ Unit Tests"]
    H --> H2["9+ Integration Tests"]
    H --> H3["158+ Doctests"]
    H --> H4["Property-based Tests"]

    I["โšก Benchmarks"] --> I1["MCMC Performance<br/>Adaptation & diagnostics"]
    I --> I2["Memory Optimization<br/>Pooling & COW traces"]

    style A fill:#e1f5fe
    style B fill:#f3e5f5
    style C fill:#e8f5e8
    style D fill:#fff3e0
    style E fill:#fce4ec
    style F fill:#ffebee
    style G fill:#f1f8e9
    style H fill:#e3f2fd
    style I fill:#fff8e1
```

### Directory Structure

```text
fugue/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ core/                   # Core probabilistic programming abstractions
โ”‚   โ”‚   โ”œโ”€โ”€ address.rs          # Hierarchical addressing system
โ”‚   โ”‚   โ”œโ”€โ”€ distribution.rs     # Type-safe distributions (10 built-in)
โ”‚   โ”‚   โ”œโ”€โ”€ model.rs            # Monadic Model<T> abstraction
โ”‚   โ”‚   โ””โ”€โ”€ numerical.rs        # Numerically stable algorithms
โ”‚   โ”œโ”€โ”€ inference/              # Inference algorithms
โ”‚   โ”‚   โ”œโ”€โ”€ mh.rs               # MCMC (Adaptive Metropolis-Hastings)
โ”‚   โ”‚   โ”œโ”€โ”€ smc.rs              # Sequential Monte Carlo
โ”‚   โ”‚   โ”œโ”€โ”€ vi.rs               # Variational Inference
โ”‚   โ”‚   โ”œโ”€โ”€ abc.rs              # Approximate Bayesian Computation
โ”‚   โ”‚   โ””โ”€โ”€ diagnostics.rs      # R-hat, ESS, validation
โ”‚   โ”œโ”€โ”€ runtime/                # Execution engine
โ”‚   โ”‚   โ”œโ”€โ”€ handler.rs          # Effect handler system
โ”‚   โ”‚   โ”œโ”€โ”€ interpreters.rs     # Built-in handlers
โ”‚   โ”‚   โ”œโ”€โ”€ trace.rs            # Execution history recording
โ”‚   โ”‚   โ””โ”€โ”€ memory.rs           # Memory optimization (pooling, COW)
โ”‚   โ”œโ”€โ”€ macros/                 # Ergonomic macros
โ”‚   โ”‚   โ””โ”€โ”€ mod.rs              # prob!, plate!, addr! macros
โ”‚   โ””โ”€โ”€ error.rs                # Comprehensive error handling
โ”œโ”€โ”€ examples/                   # 14 complete examples
โ”‚   โ”œโ”€โ”€ bayesian_coin_flip.rs
โ”‚   โ”œโ”€โ”€ linear_regression.rs
โ”‚   โ”œโ”€โ”€ mixture_models.rs
โ”‚   โ”œโ”€โ”€ hierarchical_models.rs
โ”‚   โ””โ”€โ”€ ...
โ”œโ”€โ”€ benches/                    # Performance benchmarks
โ”‚   โ”œโ”€โ”€ mcmc_benchmarks.rs      # MCMC adaptation & diagnostics
โ”‚   โ””โ”€โ”€ memory_benchmarks.rs    # Memory pooling & COW traces
โ”œโ”€โ”€ tests/                      # Integration tests
โ”œโ”€โ”€ docs/                       # User guide & documentation
โ”‚   โ”œโ”€โ”€ src/                    # mdBook source
โ”‚   โ””โ”€โ”€ api/                    # API documentation
โ””โ”€โ”€ target/                     # Build artifacts
```

## Questions?

Open an issue or start a discussion on GitHub. We're happy to help!