-
Notifications
You must be signed in to change notification settings - Fork 369
Fixed #1111 Add branching logic for sdp #1200
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
base: main
Are you sure you want to change the base?
Changes from all commits
b2221b1
5450557
61bd5b7
d01573d
a3538d1
6a48340
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -648,24 +648,104 @@ def check_window_size(m, max_size=None, n=None): | |
| warnings.warn(msg) | ||
|
|
||
|
|
||
| def sliding_dot_product(Q, T): | ||
| def make_sliding_dot_product(boundaries=None, default_func=None): | ||
| """ | ||
| Calculate the sliding window dot product. | ||
| A closure to compute the sliding dot product that allows users | ||
| to use different methods in different cases | ||
|
|
||
| Parameters | ||
| ---------- | ||
| Q : numpy.ndarray | ||
| Query array or subsequence | ||
| boundaries : nested list, default None | ||
| A list of items, where each item is a list of 3 elements: | ||
| * index 0: (LB_m, UB_m) | ||
| * index 1: (LB_n, UB_n) | ||
| * index 2: func | ||
| where, fucn is the sdp function for computing | ||
| the sliding dot product of ``Q`` and ``T``, when | ||
| m=len(Q) falls into range [LB_m, UB_m], and n=len(T) | ||
| falls into range [LB_n, UB_n]. | ||
| When this is None (default), it will automatically be set to | ||
| the following value: | ||
| [ | ||
| [ | ||
| (3, config.STUMPY_NJIT_SDP_Q_LENGTH), | ||
| (3, np.inf), | ||
| sdp._njit_sliding_dot_product, | ||
| ] | ||
| ] | ||
|
|
||
| T : numpy.ndarray | ||
| Time series or sequence | ||
| default_func : class 'function', default None | ||
| A callable object that is used for computing | ||
| the sliding dot product between a query `Q` and | ||
| time series `T`. This is used when len(Q) and len(T) | ||
| values do not fall into any boundary provided | ||
| in `boundaries`. When None (default), this will | ||
| automatically be set to `sdp._pyfftw_sliding_dot_product` | ||
| if available. If not, it will be automatically set to | ||
| `sdp._sliding_dot_product`. | ||
|
|
||
| Returns | ||
| ------- | ||
| output : numpy.ndarray | ||
| Sliding dot product between `Q` and `T`. | ||
| """ | ||
| return sdp._sliding_dot_product(Q, T) | ||
| sliding_dot_product : callable | ||
| A callable object that computes the sliding dot product between ``Q`` | ||
| and ``T`` using different methods based on len(Q) and len(T). It | ||
| internally checks the boundary in `boundaries` and choose a function | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "chooseS" |
||
| """ | ||
| stumpy_default_func = sdp._sliding_dot_product | ||
| if sdp.PYFFTW_IS_AVAILABLE: # pragma: no cover | ||
| stumpy_default_func = sdp._pyfftw_sliding_dot_product | ||
|
|
||
| if default_func is None: | ||
| default_func = stumpy_default_func | ||
|
|
||
| if boundaries is None: | ||
| boundaries = [ | ||
| # [ | ||
| # (LB_m, UB_m), | ||
| # (LB_n, UB_n), | ||
| # func | ||
| # ] | ||
| [ | ||
| (3, config.STUMPY_NJIT_SDP_Q_LENGTH), | ||
| (3, np.inf), | ||
| sdp._njit_sliding_dot_product, | ||
| ], | ||
| ] | ||
|
|
||
| def sliding_dot_product(Q, T): | ||
| """ | ||
| Compute the sliding dot product between ``Q`` and ``T`` | ||
| by using different methods according to len(Q) and len(T) | ||
|
|
||
| Parameters | ||
| ---------- | ||
| Q : numpy.ndarray | ||
| Query array or subsequence. | ||
|
|
||
| T : numpy.ndarray | ||
| Time series or sequence. | ||
|
|
||
| Returns | ||
| ------- | ||
| out : numpy.ndarray | ||
| Sliding dot product between ``Q`` and ``T``. | ||
| """ | ||
| m = len(Q) | ||
| n = len(T) | ||
| if m == n: | ||
| return np.array([np.dot(Q, T)]) | ||
|
|
||
| for item in boundaries: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's just something about this that doesn't sit right with me. Here's what I am seeing:
So, while the logic is sound, this point:
is still relevant. Yes, the sets of boundaries are supplied/embedded once into Having said that, are we going to have a way for users to run a function and come up with boundaries and functions that are best suited for their hardware?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Right, I misunderstood your point before.
Let's replace that for-loop with Is it a bad design? This allows [advanced] users to use different ways to implement branching logic for their
We can always add a caching mechanism on top of the function As a side, regarding the following question you raised before in another comment:
I think the proposal should address that
Finding "boundaries" is tricky. I have a narrower scope (and, tbh, simpler solution 😅) in mind... a function that gets
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Okay, I think it might be tricky for most users too! So, maybe they appreciate if we just come up with a function that helps them identify boundaries approximately. For instance, we just explore cases where
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am mostly interested in what the |
||
| (LB_m, UB_m), (LB_n, UB_n), func = item | ||
| if LB_m <= m <= UB_m and LB_n <= n <= UB_n: | ||
| return func(Q, T) | ||
|
|
||
| return default_func(Q, T) | ||
|
|
||
| return sliding_dot_product | ||
|
|
||
|
|
||
| sliding_dot_product = make_sliding_dot_product() | ||
|
|
||
|
|
||
| @njit( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
funcnotfucn