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

[Optimization] get_neighbours can generate n samples and then validate them #236

Closed
eddiebergman opened this issue Feb 24, 2022 · 2 comments · Fixed by #346
Closed

[Optimization] get_neighbours can generate n samples and then validate them #236

eddiebergman opened this issue Feb 24, 2022 · 2 comments · Fixed by #346

Comments

@eddiebergman
Copy link
Contributor

eddiebergman commented Feb 24, 2022

Just a note that get_neighbours could be optimized in a few places. Currently we seem to generate a number at a time and then perform valid checks and then transform, causing a lot of non-vectorized if checks.

This could be vectorized by generating n numbers, validating them together and then performing the transformation on all elements.

Just rough pseudo code

neighoubrs = np.array([])
while len(neighbours) < n:
    samples = rs.normal(value, std, size=n - len(neighbours))
    neighbours = np.append(neighbours, samples[<condition>])
    
if transform:
    neighbours = self._transform_vector(neighbours)
    
return neighbours
@eddiebergman
Copy link
Contributor Author

A more detailed (untested) algorithm can be found here:

Some Cpython analysis should be done to improve and make sure this actually speeds up over the current implementation.

@eddiebergman
Copy link
Contributor Author

This sampling was made significantly faster with a newer algorithm in #346. Implements some of the same ideas

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 a pull request may close this issue.

1 participant