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

ENH: vectorize loo function for local_constant estimator #9199

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

shilinng
Copy link

@shilinng shilinng commented Apr 7, 2024

This is a performance improvement for bandwidth estimation using leave one out cross-validation for local constant estimators. A method cv_loo_fast is added which is only used when reg_type is 'lc'. The idea is to calculate the leave-on-out estimations by using matrix multiplication instead of using a loop. In general, I see a 2~2.5 times of speed up for <=1000 rows of data. When using only continuous gaussian kernel, the speed up is more than 6 times due to a further vectorization in calculating the product kernel function.

Notes:

  • It is essential that you add a test when making code changes. Tests are not
    needed for doc changes.
  • When adding a new function, test values should usually be verified in another package (e.g., R/SAS/Stata).
  • When fixing a bug, you must add a test that would produce the bug in main and
    then show that it is fixed with the new code.
  • New code additions must be well formatted. Changes should pass flake8. If on Linux or OSX, you can
    verify you changes are well formatted by running
    git diff upstream/main -u -- "*.py" | flake8 --diff --isolated
    
    assuming flake8 is installed. This command is also available on Windows
    using the Windows System for Linux once flake8 is installed in the
    local Linux environment. While passing this test is not required, it is good practice and it help
    improve code quality in statsmodels.
  • Docstring additions must render correctly, including escapes and LaTeX.

@pep8speaks
Copy link

pep8speaks commented Apr 7, 2024

Hello @shilinng! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2024-04-07 18:26:02 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

KernelReg performance in a for loop
2 participants