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

suggestion: orders of magnitude speed-up using Numba JIT #1

Open
adrianomitre opened this issue Jul 10, 2021 · 1 comment
Open

suggestion: orders of magnitude speed-up using Numba JIT #1

adrianomitre opened this issue Jul 10, 2021 · 1 comment

Comments

@adrianomitre
Copy link

adrianomitre commented Jul 10, 2021

In my machine, the following demonstrates more than 100x speed-up.

import pandas as pd
import numpy as np
import timeit
import hampel # assumes `pip install hampel`

def much_faster_hampel(series, window_length, threshold=3):
  # Please refer to [1] for `hampel_filter_forloop_numba` implementation.
  # [1] https://gist.github.com/adrianomitre/2ced5544421eca031180782cc30798af 
  result, outlier_indices = hampel_filter_forloop_numba(series.values, window_length, threshold)
  result[outlier_indices] = np.nan
  return result

ts_len = 2**8
win_sz = 7

ts = pd.Series(np.random.rand(ts_len))

# causes JIT compilation
much_faster_hampel(ts, win_sz)

timeit.timeit(lambda: hampel.hampel(ts, win_sz), number=100)
timeit.timeit(lambda: much_faster_hampel(ts, win_sz), number=100)

Please refer to this gist for hampel_filter_forloop_numba implementation.

@dwervin
Copy link
Owner

dwervin commented Dec 25, 2022

In my machine, the following demonstrates more than 100x speed-up.

import pandas as pd
import numpy as np
import timeit
import hampel # assumes `pip install hampel`

def much_faster_hampel(series, window_length, threshold=3):
  # Please refer to [1] for `hampel_filter_forloop_numba` implementation.
  # [1] https://gist.github.com/adrianomitre/2ced5544421eca031180782cc30798af 
  result, outlier_indices = hampel_filter_forloop_numba(series.values, window_length, threshold)
  result[outlier_indices] = np.nan
  return result

ts_len = 2**8
win_sz = 7

ts = pd.Series(np.random.rand(ts_len))

# causes JIT compilation
much_faster_hampel(ts, win_sz)

timeit.timeit(lambda: hampel.hampel(ts, win_sz), number=100)
timeit.timeit(lambda: much_faster_hampel(ts, win_sz), number=100)

Please refer to this gist for hampel_filter_forloop_numba implementation.

Sorry, but you are referencing a completely different library. The library you are importing is not at all used in mine.

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

No branches or pull requests

2 participants