ApolloResearch / rib

Library for methods related to the Local Interaction Basis (LIB)
MIT License
3 stars 0 forks source link

Gauss-Legendre alpha integral, plus integral refactor #317

Closed stefan-apollo closed 5 months ago

stefan-apollo commented 6 months ago

Note: Branched of from stochastic sources branch!

Our integration via trapezoidal rule is bad because a. Cleverer methods exist b. Especially for smooth-ish functions much better methods exist c. We want to switch between alpha=1 ("gradient") and integration

This PR

  1. Refactors integration to use "weights" which replaces the old trapezoidal_scaler and interval_size. The integration result is now given by integral(f) = sum(weights*f(samples)), in practice this just replaces the trapezoidal_scaler and interval_size terms with weights
  2. Implements three functions generating "weights" and "alphas": Trapezoidal, Gradient, Gauss-Legendre. Gauss-Legendre is only one of those clever methods (though one of the best & simplest ones) but one could easily add more. This is controlled via the integration_rule config value.
  3. Renamed integrated_gradient_trapezoidal_norm to calc_basis_integrated_gradient,

Implemented tests for