Contributing
We welcome contributions to ClosedFormExpectations.jl. This page describes how to report bugs, suggest features, and contribute code.
Reporting Bugs
We track bugs using GitHub Issues. Please provide:
- Versions of Julia and
ClosedFormExpectations.jl - A minimal reproducible example
- Expected vs. actual behavior
Contributing Code
Setup
Use the dev command from the Julia package manager to install for development:
] dev git@github.com:your_username/ClosedFormExpectations.jl.gitAdding a New (Distribution, Function) Pair
To add a new closed-form expectation:
- Identify the distribution and function for which a closed-form expression exists.
- Add the implementation in the appropriate file under
src/. Follow the existing directory structure:src/Normal/for Normal-related expectationssrc/Gamma/for Gamma-related expectationssrc/Exponential/for Exponential-related expectationssrc/MvNormal/for multivariate Normal expectations
- Define a method of
BayesBase.expectationwith BayesBase's@supports_expectation, which also declares that the backend supports the pair:@supports_expectation function expectation(backend::ClosedFormExpectation, f::YourFunctionType, q::YourDistribution) # closed-form expression here end - Optionally add its gradient with
@supports_expectation_gradient:
The test "Every closed form declares its support" fails for a method defined without the macros. Add an integrand or a distribution of the new pair to the lists in@supports_expectation_gradient function expectation_gradient(backend::ClosedFormExpectation, f::YourFunctionType, q::YourDistribution) # an SVector of the derivatives with respect to the parameters of q endtest/interface/support_tests.jl: every declared pair must be computed by at least one case there, and every pair declared supported must give a finite result. - Add tests in the corresponding test file under
test/. Tests typically validate against Monte Carlo estimates using the Central Limit Theorem. - Update the documentation in
docs/src/lib/supported-pairs.md.
Running Tests
] test ClosedFormExpectationsStyle Conventions
- Follow the default Julia style guide
- Use 4 spaces for indentation
- Type names use
UpperCamelCase - Function names are
lowercasewith underscores where necessary