scales icon indicating copy to clipboard operation
scales copied to clipboard

Derivatives of transformations

Open mjskay opened this issue 3 years ago • 0 comments

This PR closes #322 by supplying derivatives of transformation functions and inverses where possible.

Specifically, it:

  • Adds two optional, may-be-NULL fields to transform objects: $d_transform and $d_inverse. These functions are the derivatives of $transform and $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 is NULL).
  • Includes tests for all of the above.

Some possible discussion points:

  • I initially used $transform_deriv and $inverse_deriv, but found that existing tests used partial matching on $trans and $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_transform and $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.

mjskay avatar Apr 03 '22 05:04 mjskay