Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic Differentiation #24

Merged
merged 54 commits into from Sep 28, 2023
Merged

Automatic Differentiation #24

merged 54 commits into from Sep 28, 2023

Conversation

pzivich
Copy link
Owner

@pzivich pzivich commented Jul 4, 2023

This branch proposes an implementation of automatic differentiation to compute the bread, as mentioned in #23. While there are libraries, like JAX, that implement this, I do not want to add dependencies. Therefore, I have implemented a version of automatic differentiation.

  • Develop autodiff functionality
  • Develop tests for popular functions we want the derivative of
  • Develop tests for all estimating equations and compare bread computations

Note that this branch is still under active development. I have not fully tested my implementation of computing the bread. Therefore, only use this branch for preliminary testing.

Note: I am planning on keeping the derivative approximation of the bread as the default. The exact derivatives are going to be an alternative option. Ultimately, any errors should lead the user to fall back to the approximation.

@pzivich pzivich added the enhancement New feature or request label Jul 4, 2023
@pzivich pzivich self-assigned this Jul 4, 2023
@pzivich pzivich linked an issue Jul 4, 2023 that may be closed by this pull request
@pzivich
Copy link
Owner Author

pzivich commented Aug 27, 2023

The addition of ee_glm might make the AD implementation a little more difficult. Specifically, the AD will need to handle the polygamma and digamma functions and be able to get their derivatives

@pzivich
Copy link
Owner Author

pzivich commented Aug 28, 2023

Okay here is how I think I handle digamma and polygamma.

  1. Write an internal polygamma function. This functions checks the input type. If it is a PrimalTangentPairs object, it calls the internal function on that object. Otherwise, it puts it into the scipy version of the polygamma function. Repeat for digamma.
  2. Add internal polygamma function to PrimalTangentPairs that correctly creates each pair. Follow syntax of polygamma. Same for digamma.

This setup should handle the new ee_glm equations by correctly sorting out the polygamma pieces into the correct spots.

The downside to this is if users wanted to use the polygamma function, they would need to would need to use my internal version when pairing with AD. Thankfully this is all avoided when using numerical approximation

@pzivich
Copy link
Owner Author

pzivich commented Sep 6, 2023

Okay I believe to have fixed my NumPy woes. Now I need to create autodiff tests for all the available estimating equations (to be safe everything works with what I provide to users).

@pzivich pzivich merged commit 099ac09 into main Sep 28, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add functionality to compute the gradient for the bread matrix
1 participant