scales
scales copied to clipboard
Derivatives of transformations
This PR closes #322 by supplying derivatives of transformation functions and inverses where possible.
Specifically, it:
- Adds two optional, may-be-
NULLfields to transform objects:$d_transformand$d_inverse. These functions are the derivatives of$transformand$inverse. - Supplies derivatives for all existing numeric transformations
- Applies the chain rule to give derivatives for
compose_trans()(unless any derivatives in the transformation are missing, in which case the corresponding derivative function isNULL). - Includes tests for all of the above.
Some possible discussion points:
- I initially used
$transform_derivand$inverse_deriv, but found that existing tests used partial matching on$transand$inv, so these names caused failures. I wasn't sure if other legacy code relies on this partial matching, so I conservatively went with the names$d_transformand$d_inverse. I am not sure these are the best names and am happy to change them. - I did not supply derivatives for the date transform. Arguably those derivatives could be a constant like
identity_trans(), at least for applications like I am imagining these will be used for (plotting densities), but I went with the more conservative choice of not including it.