Stan Submodule API Reference

Stan probabilistic programming language integration for SciStanPy.

This submodule provides comprehensive integration between SciStanPy models and the Stan probabilistic programming language, enabling high-performance Bayesian inference through Hamiltonian Monte Carlo (HMC).

The integration handles the complete workflow from SciStanPy model specifications to Stan code generation, compilation, and execution. It automatically translates Python model definitions into Stan code while preserving the probabilistic structure and mathematical relationships.

Key Components:
  • Automatic Code Generation: Converts SciStanPy models to Stan language

  • Compilation Management: Handles Stan-to-C++ compilation with caching

  • Sampling Interface: Provides high-level interface to Stan sampling algorithms

  • Custom Functions: Extends Stan with SciStanPy-specific mathematical functions

  • Diagnostics Integration: Incorporates Stan’s comprehensive MCMC diagnostics

Custom Extensions:

The submodule includes custom Stan functions that extend the base language with SciStanPy-specific mathematical operations. These functions are automatically included in generated Stan programs and provide:

  • Specialized probability distributions

  • Custom transformation functions

  • Optimized mathematical operations

  • SciStanPy-specific utility functions

This submodule is organized into two main components:

  1. A series of stanfunctions files that define custom Stan functions for use in SciStanPy models.

  2. The stan_model module that handles the conversion of SciStanPy models into Stan code, manages compilation, and provides interfaces for running inference.

There is also a single global configuration variable defined at the submodule level:

scistanpy.model.stan.STAN_INCLUDE_PATHS

A list of absolute paths used by the Stan code assembly step to locate bundled Stan function snippets and headers.