A model is defined in it’s own package. The model must
model.Model. In the model’s source code:
- Method Observe of interface
- All methods on the type implementing
- Within the methods, the following is differentiated:
- assignments to
float64(including parallel assignments if all values are of type
- returns of float64;
- standalone calls to methods on the type implementing model.Model (apparently called for side effects on the model).
- assignments to
- Imported package name
- Non-dummy identifiers starting with the prefix for
generated identifiers (
_by default) are reserved.
Derivatives do not propagate through a function that is not an elemental or a call to a model method. If a derivative is not registered for an elemental, calling the elemental in a differentiated context will cause a run-time error.
Functions are considered elementals (and must have a registered derivative) if their signature is of kind
func (float64, float64*) float64
that is, one or more non-variadic
float64 argument and
float64 return value. For example, function
func (float64, float64, float64) float64
is considered elemental, while functions
func (...float64) float64 func (float64) float64 func (int, float64) float64
are not. Gradients for selected functions from the
package are pre-defined (
Tan). Auxiliary elemental functions with pre-defined
gradients are in
Distributions are models. Several distributions are provided in
In addition to the
Observe method, distributions have
(single observation) and
Logps (multiple observations) methods
which accept distribution parameters and observations as
individual arguments rather than in a single slice.
deriv is used to differentiate a model.
The command-line syntax is:
deriv -h for the full list of command-line options. The
differentiated model is put into subpackage “ad” of the model’s
package, with the same name as the original package.
- optimization via gradient ascent methods.
- full posterior inference via Hamiltonian Monte Carlo variants.
DepthAdapter enables adaption of NUTS step size with respect to the average