Skip to content

Add Matrix Profile Subspace For MSTUMP/MSTUMPED #188

Closed

Description

@seanlaw

Following Definition 13 in the mSTAMP paper we can return a "matrix profile subspace"

Activity

  1. self-assigned this
    on May 27, 2020
  2. added
    enhancement
    on May 27, 2020
  3. seanlaw commented on May 27, 2020

    @seanlaw
    ContributorAuthor

    This is actually a little bit tricky when include is used since the include rows are being swapped and therefore the row indices are mixed up. This shouldn't be an issue when include is not used.

  4. mihailescum commented on May 27, 2020

    @mihailescum
    Contributor

    Don't you also do some sorting with include? Shouldn't 8t be possible to just prepend the indices that have to be included?

  5. seanlaw commented on May 27, 2020

    @seanlaw
    ContributorAuthor

    @mexxexx That's what I thought originally but argsort isn't smart enough to know that you are operating on the remaining array and ends up reseting the indices starting from zero. And it isn't enough to simply add a constant (equal to the len(include)) to the argsort'ed indices since the location of where the include indices are will affect the indices output from argsort.

    Let's say one of my columns of D is:

    D = np.array([[3],
                  [9],
                  [1],
                  [4],
                  [2]])
    

    And include = [1, 2]. The correct subspace array that we'd want is:

    S = np.array([[1],
                  [2],
                  [4],
                  [0],
                  [3]])
    

    However, in our current implementation, we swap the indices in include first and so we modify our D array to:

    D = np.array([[9],
                  [1],
                  [3],
                  [4],
                  [2]])
    

    And we can prepend the indices as you had pointed out:

    S = np.array([[1],
                  [2],
                  [?],
                  [?],
                  [?]])
    

    and then we'd maybe argsort the last 3 rows with:

    S[len(include):] = D[len(include):].argsort(axis=0, kind='mergesort')
    

    but this would produce:

    S = np.array([[1],
                  [2],
                  [2],
                  [0],
                  [1]])
    

    Notice how the last three rows have no "knowledge" of the first two rows ofD. And it is not enough to add len(include):

    S[len(include):] = D[len(include):].argsort(axis=0, kind='mergesort') + len(include)
    

    and get this wrong answer:

    S = np.array([[1],
                  [2],
                  [4],
                  [2],
                  [3]])
    
    # Remember, we really want
    # S = np.array([[1],
    #               [2],
    #               [4],
    #               [0],
    #               [3]])
    

    So, the tricky part is keeping track of when a distance gets "displaced" by an include index and somehow account for that "change in index". Again, it's more of a nuisance but let me know if that makes sense and if you have an ideas :)

  6. seanlaw commented on May 28, 2020

    @seanlaw
    ContributorAuthor

    So, I actually track the displacement of the indices and I think it can be done trivially now.

    None of this should affect the default case (i.e., no include). The discords case should be straightforward but care is needed with include added to it.

  7. seanlaw commented on May 28, 2020

    @seanlaw
    ContributorAuthor

    Okay, I figure it out. For completeness and transparency, I'm leaving my tests (which all pass) here:

    import numpy as np
    import numpy.testing as npt
    
    D = np.array([[0, 9],
                  [3, 4],
                  [9, 3],
                  [1, 2],
                  [4, 1],
                  [2, 5]])
    
    def func(D, include=None, discords=False):
    
        S = np.empty(D.shape, dtype=np.int64)
        if include is not None:
            tmp_swap = np.empty((include.shape[0], D.shape[1]))
            restricted_indices = include[include < include.shape[0]]
            unrestricted_indices = include[include >= include.shape[0]]
            mask = np.ones(include.shape[0], bool)
            mask[restricted_indices] = False
            
        # Compute D
        D = D.copy()
    
        start_row_idx = 0
        if include is not None:
            tmp_swap[:] = D[: include.shape[0]]
            D[: include.shape[0]] = D[include]
            D[unrestricted_indices] = tmp_swap[mask]
            start_row_idx = include.shape[0]
    
        if discords:
            S[start_row_idx:] = D[start_row_idx:].argsort(axis=0, kind='mergesort')[::-1]
        else:
            S[start_row_idx:] = D[start_row_idx:].argsort(axis=0, kind='mergesort')
        D[start_row_idx:] = np.take_along_axis(D[start_row_idx:], S[start_row_idx:], axis=0)
        
        if include is not None:
            repeat_include = np.transpose([include] * S.shape[1])
            S[:start_row_idx, :] = repeat_include
            
            displaced_indices = np.arange(include.shape[0])[mask]
            lookup = np.arange(D.shape[0])
            lookup[unrestricted_indices] = displaced_indices
            S[start_row_idx:] += start_row_idx
            S[start_row_idx:] = lookup[S[start_row_idx:]]
        
        return D, S
    
    
    left_D, left_S = func(D)
    right_D = np.array([[0, 1],
                        [1, 2],
                        [2, 3],
                        [3, 4],
                        [4, 5],
                        [9, 9]
                       ])
    right_S = np.array([[0, 4],
                        [3, 3],
                        [5, 2],
                        [1, 1],
                        [4, 5],
                        [2, 0]
                       ])
    npt.assert_almost_equal(left_D, right_D)
    npt.assert_almost_equal(left_S, right_S)
    
    
    left_D, left_S = func(D, include=np.array([1,2]))
    right_D = np.array([[3, 4],
                        [9, 3],
                        [0, 1],
                        [1, 2],
                        [2, 5],
                        [4, 9]
                       ])
    right_S = np.array([[1, 1],
                        [2, 2],
                        [0, 4],
                        [3, 3],
                        [5, 5],
                        [4, 0]
                       ])
    npt.assert_almost_equal(left_D, right_D)
    npt.assert_almost_equal(left_S, right_S)
    
    
    left_D, left_S = func(D, include=np.array([2,3,4]))
    right_D = np.array([[9, 3],
                        [1, 2],
                        [4, 1],
                        [0, 4],
                        [2, 5],
                        [3, 9]
                       ])
    right_S = np.array([[2, 2],
                        [3, 3],
                        [4, 4],
                        [0, 1],
                        [5, 5],
                        [1, 0]
                       ])
    npt.assert_almost_equal(left_D, right_D)
    npt.assert_almost_equal(left_S, right_S)
    
    
    left_D, left_S = func(D, include=np.array([0,1]))
    right_D = np.array([[0, 9],
                        [3, 4],
                        [1, 1],
                        [2, 2],
                        [4, 3],
                        [9, 5]
                       ])
    right_S = np.array([[0, 0],
                        [1, 1],
                        [3, 4],
                        [5, 3],
                        [4, 2],
                        [2, 5]
                       ])
    npt.assert_almost_equal(left_D, right_D)
    npt.assert_almost_equal(left_S, right_S)
    
    
    left_D, left_S = func(D, include=np.array([4,5]))
    right_D = np.array([[4, 1],
                        [2, 5],
                        [0, 2],
                        [1, 3],
                        [3, 4],
                        [9, 9]
                       ])
    right_S = np.array([[4, 4],
                        [5, 5],
                        [0, 3],
                        [3, 2],
                        [1, 1],
                        [2, 0]
                       ])
    npt.assert_almost_equal(left_D, right_D)
    npt.assert_almost_equal(left_S, right_S)
    
    
    left_D, left_S = func(D, discords=True)
    right_D = np.array([[9, 9],
                        [4, 5],
                        [3, 4],
                        [2, 3],
                        [1, 2],
                        [0, 1]
                       ])
    right_S = np.array([[2, 0],
                        [4, 5],
                        [1, 1],
                        [5, 2],
                        [3, 3],
                        [0, 4]
                       ])
    npt.assert_almost_equal(left_D, right_D)
    npt.assert_almost_equal(left_S, right_S)
    
    
    left_D, left_S = func(D, include=np.array([1,2]), discords=True)
    right_D = np.array([[3, 4],
                        [9, 3],
                        [4, 9],
                        [2, 5],
                        [1, 2],
                        [0, 1]
                       ])
    right_S = np.array([[1, 1],
                        [2, 2],
                        [4, 0],
                        [5, 5],
                        [3, 3],
                        [0, 4]
                       ])
    npt.assert_almost_equal(left_D, right_D)
    npt.assert_almost_equal(left_S, right_S)
    
    
    left_D, left_S = func(D, include=np.array([2,3,4]), discords=True)
    right_D = np.array([[9, 3],
                        [1, 2],
                        [4, 1],
                        [3, 9],
                        [2, 5],
                        [0, 4]
                       ])
    right_S = np.array([[2, 2],
                        [3, 3],
                        [4, 4],
                        [1, 0],
                        [5, 5],
                        [0, 1]
                       ])
    npt.assert_almost_equal(left_D, right_D)
    npt.assert_almost_equal(left_S, right_S)
    
    
    left_D, left_S = func(D, include=np.array([0, 1]), discords=True)
    right_D = np.array([[0, 9],
                        [3, 4],
                        [9, 5],
                        [4, 3],
                        [2, 2],
                        [1, 1]
                       ])
    right_S = np.array([[0, 0],
                        [1, 1],
                        [2, 5],
                        [4, 2],
                        [5, 3],
                        [3, 4]
                       ])
    npt.assert_almost_equal(left_D, right_D)
    npt.assert_almost_equal(left_S, right_S)
    
    
    left_D, left_S = func(D, include=np.array([4,5]), discords=True)
    right_D = np.array([[4, 1],
                        [2, 5],
                        [9, 9],
                        [3, 4],
                        [1, 3],
                        [0, 2]
                       ])
    right_S = np.array([[4, 4],
                        [5, 5],
                        [2, 0],
                        [1, 1],
                        [3, 2],
                        [0, 3]
                       ])
    npt.assert_almost_equal(left_D, right_D)
    npt.assert_almost_equal(left_S, right_S)
    
  8. seanlaw commented on May 28, 2020

    @seanlaw
    ContributorAuthor

    And, yes, I did all of those computations by hand in order to compare it to the computed answer 😄

  9. seanlaw commented on May 29, 2020

    @seanlaw
    ContributorAuthor

    @mexxexx I need your help making sure my conceptual understanding is correct.

    Let's say we have an M-dimensional time series and, for a single subsequence, we compare this subsequence to the rest of the time series within its dimension and compute the Distance profiles:

    D = [[ 1, 3, 5, 7],
         [10, 2, 5, 9],
         [20, 6, 0, 4]]
    

    Again, this is the distance profile for one subsequence from each dimension. And then you sort along each column:

    D_sorted = [[ 1, 2, 0, 4],
                [10, 3, 5, 7],
                [20, 6, 5, 9]]
    

    or the indices from sorting D (via argsort):

    D_sorted_idx = [[0, 1, 2, 2],
                    [1, 0, 0, 0],
                    [2, 2, 1, 1]]
    

    And then perform a running average along each column (D_prime_prime):

    # The numbers are rounded for presentation purposes
    D_prime_prime = [[ 1.0,  2.0, 0.0, 4.0],
                     [ 5.5,  2.5, 2.5, 5.5],
                     [10.3,  3.7, 3.3, 6.7]]
    

    So, the matrix profile indices (computed by taking the argmin along each row) and matrix profile are:

    I = [[2],
         [1],
         [2]]
    
    P = [[0.0],
         [2.5],
         [3.3]]
    

    What should the matrix profile subspace be in this example?? Is it:

    S = [[2],
         [0],
         [1]]
    

    Practically, we are doing something like S = D_sorted_idx[I]. Does that sound right?

    If I understand correctly, the matrix profile subspace for this single subsequence should be the same shape as I and P?

  10. seanlaw commented on May 29, 2020

    @seanlaw
    ContributorAuthor

    I am re-reading this comment that you made a few days ago as I misunderstood it.

  11. mihailescum commented on May 29, 2020

    @mihailescum
    Contributor

    I think you mistyped something. The third column of D_sorted doesn't look right.

  12. seanlaw commented on May 29, 2020

    @seanlaw
    ContributorAuthor

    I think you mistyped something. The third column of D_sorted doesn't look right.

    Ooops. How about now?

  13. mihailescum commented on May 29, 2020

    @mihailescum
    Contributor

    Initially, I thought of D_sorted_indices[I] too, so S=[[2],[0],[1]].

    However, seeing this example, this doesn't look right. To get the the matrix profile value of dimension 2 we would need to sum dimensions 1 and 0 at index 1, but looking at S in the current form, we would take dimensions 2 and 0... So it appears to be more complicated... I have to reread the definition...

  14. mihailescum commented on May 30, 2020

    @mihailescum
    Contributor

    After thinking about it, I think when the authors write "k-dimensional ..." They mean a fixed k. So in our case we would need d profile subspaces, one for each dimension. We could either return a list of subspaces or put them all in one array of dimension d(d+1)/2 (1+2+3+...+d dimensions)

  15. seanlaw commented on May 30, 2020

    @seanlaw
    ContributorAuthor

    Can you show me what a subspace for each of k=1, k=2, and k=3 would be for my example above? And then what the d(d +1)/2 might look like?

    When does memory become an issue?

  16. 36 remaining items

  17. seanlaw commented on Dec 17, 2020

    @seanlaw
    ContributorAuthor

    Okay, as I think about it even more, I believe that the calculation of the subspace can be simplified even further. Right now, I am re-computing the full distance profile for each dimension. Instead, since we already know the index location of the nearest neighbor, we don't actually need the full distance profile. I need to play around with this.

  18. seanlaw commented on Dec 17, 2020

    @seanlaw
    ContributorAuthor

    Cool. It looks like we can just do this:

    def subspace(T, m, motif_idx, nn_idx, include=None, discords=False):
        start_row_idx = 0
        S = np.empty(T.shape[0], dtype=object)
        D = np.linalg.norm(core.z_norm(T[:, motif_idx : motif_idx + m], axis=1) - core.z_norm(T[:, nn_idx : nn_idx + m], axis=1), axis=1)
        
        if include is not None:
            _apply_include(D, include)
            start_row_idx = include.shape[0]
    
        if discords:
            sorted_idx = D[start_row_idx:][::-1].argsort(axis=0, kind="mergesort")
        else:
            sorted_idx = D[start_row_idx:].argsort(axis=0, kind="mergesort")
        
        for k in range(T.shape[0]):
            S[k] = sorted_idx[: k + 1]
        
        return S
    
  19. mihailescum commented on Dec 17, 2020

    @mihailescum
    Contributor

    Great! Could you remind me once again, what the subspace actually was? It's been quite some time 😄

    No problem! I hope everything is going well for you.

    By the way, thank you for asking! I'm doing fine, I restarted my studies and they really keep me busy, even though everything is online of course 😄 I hope you and your family are doing fine an well too :)

  20. seanlaw commented on Dec 18, 2020

    @seanlaw
    ContributorAuthor

    Great! Could you remind me once again, what the subspace actually was? It's been quite some time 😄

    Yes, absolutely. So, you may recall that when we have a d-dimensional time series that not all d dimensions will contain a motif and that, perhaps, only k out of d dimensions are actually useful. So, for the kth dimension of a d-dimensional matrix profile, we choose the k smallest distances (amongst the d) and return the average distance but, currently, we do not return any information as to which k time series that the averaged distance is computed from. Thus, for each dimension of the d-dimensional matrix profile, the "subspace" basically tells you precisely which subset of the time series to use in order to re-compute the matrix profile distance for the kth dimension. Once we have the subspace then we can determine (using the minimum description length principle - MDL) which k dimensions (or time series) to use for extracting motifs. Does that make sense? Btw, I feel like I'm just reminding you of what you explained to me! 😃

    By the way, thank you for asking! I'm doing fine, I restarted my studies and they really keep me busy, even though everything is online of course 😄 I hope you and your family are doing fine an well too :)

    Glad to hear that and best of luck! We are doing well and optimistic for the vaccine

  21. mihailescum commented on Dec 18, 2020

    @mihailescum
    Contributor

    Does that make sense?

    Ah yes, great! So right, it just tells you the order of importance of the different dimensions at every point in time. Have you been able to understand the MDL approach? I remember that it was hard to follow what exactly they where trying to do, even if the idea seamed to make sense.

    I like the notebook example! Maybe it could be helpful, to combine the last plot together with the subspace information. I'm thinking about the following: Move the cell computing the subspace below the plot. Then maybe some text explaining how the subspace relates to what we see, along the lines of "We can see in the plot above, that the motif can be visually identified to be in the 1st and 2nd dimension. If we compare this with the matrix profile subspace, it tells us, the the most important dimension is dimension 2 (the first subspace), the second most important dimension is dimension 1 (as the second subspace contains dimension 1 on top of dimension 2) and the third dimension is the last important one. If we compare the MP values for k-dimensions, we see that looking at the two most important dimensions is almost as good as looking at only one dimension (1.07 vs. 1.0), while looking at three dimensions substantially increases the MP value (more than double!). As a motif should always contain as many dimensions as possible to contain the most information possible while excluding noise (which is why you don't want to look at all three dimensions), we conclude that the motif we found indeed lies in the first two dimensions, confirming the visual guess".

    I'm sure you come up with a better explanation, but I'm sure this would help and even without MDL automating the procedure giving interested users an idea of what they should be looking for.

  22. seanlaw commented on Dec 18, 2020

    @seanlaw
    ContributorAuthor

    Ah yes, great! So right, it just tells you the order of importance of the different dimensions at every point in time. Have you been able to understand the MDL approach? I remember that it was hard to follow what exactly they where trying to do, even if the idea seamed to make sense.

    I think I have a general grasp of the MDL approach. Basically, for each dimension of your matrix profile, you compute the corresponding subspace and you are trying to use MDL to assess the "compressibility" of the motif and its nearest neighbor. So, in the tutorial example, with 1 and 2 dimensions, the motif and nearest neighbors are very similar and therefore highly "compressible" (i.e., it takes less bits to represent the motifs/nearest neighbors across multiple time series). Once you add the third dimension then the compressibility decreases and the number of necessary bits increases. The way I think about this is similar to k-means clustering where you have to choose the right number of clusters to best represent the data or choosing the minimum number of principle components in PCA that are needed to approximately represent the variance of the data.

    Nonetheless, I think I can figure out the MDL part and it should complete the tools necessary to use mstump effectively. Although, I'm not even sure anybody is using it 😄

    I like the notebook example! Maybe it could be helpful, to combine the last plot together with the subspace information. I'm thinking about the following: Move the cell computing the subspace below the plot. Then maybe some text explaining how the subspace relates to what we see, along the lines of "We can see in the plot above, that the motif can be visually identified to be in the 1st and 2nd dimension. If we compare this with the matrix profile subspace, it tells us, the the most important dimension is dimension 2 (the first subspace), the second most important dimension is dimension 1 (as the second subspace contains dimension 1 on top of dimension 2) and the third dimension is the last important one. If we compare the MP values for k-dimensions, we see that looking at the two most important dimensions is almost as good as looking at only one dimension (1.07 vs. 1.0), while looking at three dimensions substantially increases the MP value (more than double!). As a motif should always contain as many dimensions as possible to contain the most information possible while excluding noise (which is why you don't want to look at all three dimensions), we conclude that the motif we found indeed lies in the first two dimensions, confirming the visual guess".

    Cool! I think we're roughly on the same page here. My plan is to finish MDL and then update the tutorial with the subspace and MDL. It's still a work in progress but it kinda helped to step away from it for a while and then come back to it with a fresh lens. Btw, after thinking about it a bit more (thanks to your questions), the subspace function is actually a bit more tricky when one wants to incorporate include and discords but I think it should really be:

    def subspace(T, m, motif_idx, nn_idx, include=None, discords=False):
        T, _, _ = core.preprocess(T, m)
    
        S = np.empty(T.shape[0], dtype=object)
        D = np.linalg.norm(
            core.z_norm(T[:, motif_idx : motif_idx + m], axis=1)
            - core.z_norm(T[:, nn_idx : nn_idx + m], axis=1),
            axis=1,
        )
    
        if include is not None:
            include = _preprocess_include(include)
        else:
            include = []
    
        if discords:
            D[include] = np.inf
            sorted_idx = D[::-1].argsort(axis=0, kind="mergesort")
        else:
            D[include] = 0.0
            sorted_idx = D.argsort(axis=0, kind="mergesort")
    
        for k in range(T.shape[0]):
            S[k] = sorted_idx[: k + 1]
    
        return S
    

    The fundamental difference from before (where we were directly sorting distances inplace) is that, here, we are sorting distances and returning indices and if you call argsort with a subset of rows then argsort has no knowledge of "relative indices" (i.e., all subset of rows will have indices renumbered starting from 0). It was a bit tricky but I figured out a nice work around. So, if a row (i.e., time series) is to be included then I simply set that row's distances to zero, which, when sorted, will force that row to be included. Conversely, for a time series to be included in a discord, I set the distances for those rows to np.inf. I think this is a pretty elegant way to approach it for now.

    Since the subspace code is so straightforward, I might call MDL within the subspace code and return back the subspace and the MDL value for each dimension. Both are pretty cheap computations.

    I'm sure you come up with a better explanation, but I'm sure this would help and even without MDL automating the procedure giving interested users an idea of what they should be looking for.

    Our discussions have helped tremendously! Thank you

    Of course, the ultimate goal is to add these tools to the motif searching module that you were working on.

  23. mihailescum commented on Dec 26, 2020

    @mihailescum
    Contributor

    First of all, happy holidays!

    I've been thinking about all of this a bit more, and I'm not so sure about this whole approach. I remember that also when reading the paper, I was not totally convinced. As you explain, the MDL approach is similar to the elbow technique one can use with k-means. But is this really something we want to force on the user? There might be alternatives or domain knowledge going into the decision, and having such high level 'estimators' always seems a bit like giving the machines to much control and removing the critical human interaction.

    Maybe this is a bit narrow minded, and I definitely don't want to make the impression that the tool is useful. In k-means the elbow method probably is one of the best unsupervised options one could aim for. I am not sure how scipy handles this. I know that when you apply k-means, you have to select the number of clusters, so there definitely is no builtin solution, but are there any submodules/packages that provide this sort of post processing?

    It could be worth the consideration of having stuff as MDL separately, so that it is opt-in (an even more separated than some flag you would pass to a function), but I'm not sure if the details of MDL would allow such a separation or if everything is much more interleaved than I think. At least for k-means, an elbow function can be implemented very easily without interfering with the algorithm itself. Maybe having mstump producing the MP, MPI and subspaces would be enough to then have this information consumed by some separate MDL function/module.

    Nonetheless, I think I can figure out the MDL part and it should complete the tools necessary to use mstump effectively. Although, I'm not even sure anybody is using it 😄

    Well, you never know who might need it in the future 😄 although probably its not too bad to have this whole thing on low priority for the moment.

  24. seanlaw commented on Dec 27, 2020

    @seanlaw
    ContributorAuthor

    First of all, happy holidays!

    Happy holidays to you and your family as well! One day, you'll have to mail me some authentic "lebkuchen" 😄

    I've been thinking about all of this a bit more, and I'm not so sure about this whole approach. I remember that also when reading the paper, I was not totally convinced. As you explain, the MDL approach is similar to the elbow technique one can use with k-means. But is this really something we want to force on the user? There might be alternatives or domain knowledge going into the decision, and having such high level 'estimators' always seems a bit like giving the machines to much control and removing the critical human interaction.

    So, it's interesting that you say this. I've been digging through all of the MDL literature and trying desperately to understand how one computes the MDL and, honestly, it's not as straightforward or clear as I had hoped. It's actually quite complicated and super nuanced. It's even nastier when you have to deal with multiple dimensions and I don't agree with some of the choices that were made in the Matlab code (probably because I don't fully understand everything). Thus, I agree with you in and I am not convinced about MDL either! The MDL framework feels rather weak/partially formed in comparison to the rest of the matrix profile ideas. I don't want to offer users a tool that I'll need to spend a ton of time explaining/defending especially since it feels somewhat ambiguous.

    Maybe this is a bit narrow minded, and I definitely don't want to make the impression that the tool is useful. In k-means the elbow method probably is one of the best unsupervised options one could aim for. I am not sure how scipy handles this. I know that when you apply k-means, you have to select the number of clusters, so there definitely is no builtin solution, but are there any submodules/packages that provide this sort of post processing?

    This is a valid point and I've not come across anything myself.

    It could be worth the consideration of having stuff as MDL separately, so that it is opt-in (an even more separated than some flag you would pass to a function), but I'm not sure if the details of MDL would allow such a separation or if everything is much more interleaved than I think. At least for k-means, an elbow function can be implemented very easily without interfering with the algorithm itself. Maybe having mstump producing the MP, MPI and subspaces would be enough to then have this information consumed by some separate MDL function/module.

    I think mstump can/should only return MP and MPI and one must compute the subspace separately since you first need to choose a motif subsequence to compute a subspace for (and then iterate). In case you forgot, the subspace work is a post-processing step. At least, I am confident that the subspace code is correct. My main problem right now is that I don't know how to "wrap up" the mstump tutorial. We can compute the multi-dimensional matrix profile, we can identify the top motif, and we can compute the corresponding subspace for each dimension, but we don't have a good way to indicate which dimension to choose as you iterate and identify the next motif. The mstump paper refers to this as a "subdimensional motif" (i.e., not all dimensions matter so choose a subset of the dimensions to find the best motif) and I've tried to hunt this down in the literature but without any luck. This rationale is missing from the tutorial explanation and I was hoping that MDL would fill this gap but MDL falls far short and now we don't have an acceptable or easily interpretable way to help the user select the k "subdimensions" out of the d dimensions. It's not clear to me why the matrix profile value along each dimension (which is an averaged across dimensions) isn't sufficient for choosing k, though, I haven't put much thought into this.

    I can definitely write MDL separately from mstump and the subspace code (or leave it out altogether) so no worries there. I just feel like the multi-dimensional matrix profile computed by mstump is less useful or incomplete. I don't think we need to be perfect in selecting k (nor can we expect to be) but feel like it would be really helpful to provide one simple, interpretable alternative for selecting k (after you've computed MP, MPI, and retrieved the, say, top 20 motifs and along with their subspaces along all d dimensions). Do you have any thoughts on what that "alternative" could be?

    Thanks again for bringing this up and sharing your thoughts. I was feeling very stuck and disappointed that I couldn't make MDL work! 😞

  25. mihailescum commented on Dec 27, 2020

    @mihailescum
    Contributor

    Happy holidays to you and your family as well! One day, you'll have to mail me some authentic "lebkuchen" 😄

    Does Lebkuchen actually exists in the US? 😄 Or do you remember it from your time in Europe?

    I don't want to offer users a tool that I'll need to spend a ton of time explaining/defending especially since it feels somewhat ambiguous.

    I think this makes a lot of sense!

    In case you forgot, the subspace work is a post-processing step.

    Right, thank you for reminding me. returning the subspace would be very resource unfriendly.

    My main problem right now is that I don't know how to "wrap up" the mstump tutorial. We can compute the multi-dimensional matrix profile, we can identify the top motif, and we can compute the corresponding subspace for each dimension, but we don't have a good way to indicate which dimension to choose as you iterate and identify the next motif.

    Why don't do manually, what MDL is trying to solve? In the end, MDL is a way to find the elbow in a curve. I think it would be enough to plot for each motif plot the MP values, and then argue that the best k can be spotted visually modulo maybe a few dimensions (say your time series has twenty dimensions, then from the elbow plot it might not be clear which k to chose exactly, but it would be still a very good indication).

    For example in the top motif of the tutorial, we have MP values of 1, 1.07, and 2.1 (or so). Plotting this, one sees very clearly that the "right" k should be two.

  26. seanlaw commented on Dec 27, 2020

    @seanlaw
    ContributorAuthor

    Does Lebkuchen actually exists in the US? 😄 Or do you remember it from your time in Europe?

    No, my PhD advisor was German and so his parents would mail him Lebkuchen and other German treats as the holidays approached and so he would share some with us every year 😋

    Why don't do manually, what MDL is trying to solve? In the end, MDL is a way to find the elbow in a curve. I think it would be enough to plot for each motif plot the MP values, and then argue that the best k can be spotted visually modulo maybe a few dimensions (say your time series has twenty dimensions, then from the elbow plot it might not be clear which k to chose exactly, but it would be still a very good indication).

    Okay, I can do that. I know that there are some knee/elbow finding algorithms (like "kneedle") and I'll write it as a function in the tutorial but will exclude it from STUMPY. Actually, maybe I will just plot it as you said and pick it out by eye and then direct people to the kneed if they want to automate it themselves.

    For example in the top motif of the tutorial, we have MP values of 1, 1.07, and 2.1 (or so). Plotting this, one sees very clearly that the "right" k should be two.

    Sounds good. I plan to add a few more extra decoy (random walk) time series to the original three and repeat the process and, hopefully, that will really drive home the story and the knee finding approach.

    I really appreciate you taking the time to talk through this with me! It makes the decision making so much better/easier 👍

  27. mihailescum commented on Dec 28, 2020

    @mihailescum
    Contributor

    That sounds reasonable! There is probably no need to overcomplicate things at the moment.

    I really appreciate you taking the time to talk through this with me! It makes the decision making so much better/easier

    Sure, you're welcome!

    When I'll have some more free time I will try to wrap up the motif discovery and then hopefully all these longstanding issues can be closed 😄

  28. seanlaw commented on Dec 28, 2020

    @seanlaw
    ContributorAuthor

    When I'll have some more free time I will try to wrap up the motif discovery and then hopefully all these longstanding issues can be closed

    That would be great. Let me know if/how I can help!

  29. seanlaw commented on Dec 30, 2020

    @seanlaw
    ContributorAuthor

    Alright @mexxexx I've finally completed the MSTUMP tutorial! If you have the time, would you mind reading it over and letting me know what you think?

  30. mihailescum commented on Dec 31, 2020

    @mihailescum
    Contributor

    First of all, I really like the way everything is structured and it becomes very clear how to use stumpy once you understood mstump and what can be achieved with it. This is really great and helpful! Also the subspace and discord part is clear.

    One thing which would be very cool but maybe goes out of scope of the tutorial, would be to come back to the introductory "boxer" example. The toy dataset of course has its advantage for presenting the theory, but it would be very cool to actually see mstump in action solving the originally described problem. Maybe as a final "hands-on" section?

    I have a bit trouble to follow the theoretical explanation of the multi-dimensional MP. I can understand that it is very difficult to explain it, because all this averaging that is happening is not very intuitive (at least to me). Maybe a graphic would help here. I tried to write down a better explanation for some time, but failed, so I can just give some ideas:

    1. Define what the k dimensional distance between two subsequences actually means. Here it is very important that the reader understands that we can actually define multiple k-dimensional distances, depending on which dimensions we consider. (Side note: explain that the distance is the sum of the selected one dimensional distances averaged over the number of included dimensions. This averaging might not seem intuitive, if one compares with the usual euclidean distance for points, but is made to keep different numbers of included dimensions comparable).
    2. After this explain that for each combination of included dimensions, one builds a separate k-dimensional distance profile for a given subsequence T_i, which encodes the difference of each subsequence to T_i.
    3. Now to the k-th dimensional MP: explain that the 1D matrix profile is the distance to the nearest neighbor. So the k-dimensional matrix profile value at i is the minimal distance across all possible combinations of k dimensions.
    4. The naive approach has to compute has to compute 2^d * l distance profiles (at each subsequence one would have to calculate all possible 1-distance profiles, 2-distance profiles, ...), but the mstump algorithm at each step actually requires only the computation of d distance profile, reducing the complexity to d * l. I would ignore technical details here.

    Hopefully you understand what I mean. While the general idea of mstump is actually not that difficult, I find it a nightmare to explain 😄

  31. seanlaw commented on Dec 31, 2020

    @seanlaw
    ContributorAuthor

    Thanks, @mexxexx! I agree that the mstump explanation is really hard to get right since there is a bit of jargon and, to some extent, I am trying to balance being vague and being verbose.

    Let me digest your wonderful points and take some time to figure out how to best incorporate them.

    I will look into the boxing example again as it has been a while but I vaguely remember the data requiring a fair bit of pre-processing. Nonetheless, I will take a look!

    Thanks again and happy new year!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementhelp wanted

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions