speed up the encoder kde by not calling np.histogram on the hot path#16
Open
jl33-ai wants to merge 1 commit into
Open
speed up the encoder kde by not calling np.histogram on the hot path#16jl33-ai wants to merge 1 commit into
jl33-ai wants to merge 1 commit into
Conversation
963dbd4 to
d528ecf
Compare
d528ecf to
b5ea273
Compare
The per spike kde in get_joint_prob was spending about two thirds of its time inside np.histogram. When you give np.histogram an explicit array of bin edges it cannot assume the bins are evenly spaced, so it does a binary search for every sample to find its bin. Our position bins are always the evenly spaced integers 0 to num_bins, so the bin is just the integer part of the position. Working it out directly and summing with np.bincount does the same thing and is a lot faster. Two more changes on top of that. I preallocate the scratch arrays the kde uses instead of making a fresh set on every spike, and I fuse the squared distance into a single np.einsum pass instead of squaring and then summing. On a full 50k mark buffer the median per spike time goes from about 2096 to 635 microseconds, roughly 3.3 times faster. The result is the same to within floating point rounding, about 3e-13. The config option encoder.mark_kernel.exact_histogram restores the exact original numerics if you ever need them back. Adds a small benchmark in benchmarks and a writeup in docs.
b5ea273 to
6a85435
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Makes the per spike encoder kde about 3.3x faster: median goes from 2096 to 635 microseconds at a full 50k mark buffer.