How to use the matrixprofile.distanceProfile function in matrixprofile

To help you get started, we’ve selected a few matrixprofile examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github target / matrixprofile-ts / matrixprofile / matrixProfile.py View on Github external
mp, mpIndex = _self_join_or_not_preprocess(tsA, tsB, m)

    # determine sampling size
    sample_size = math.ceil((n - m + 1) * sampling)
    
    # generate indices to sample and split based on n_threads
    if random_state is not None:
        np.random.seed(random_state)
    
    indices = np.arange(n - m + 1)
    indices = np.random.choice(indices, size=sample_size, replace=False)
    indices = np.array_split(indices, n_threads)
    
    # create pool of workers and compute
    with multiprocessing.Pool(processes=n_threads) as pool:
        func = partial(distanceProfile.mass_distance_profile_parallel, tsA=tsA, tsB=tsB, m=m)
        results = pool.map(func, indices)
    
    # The overall matrix profile is the element-wise minimum of each sub-profile, and each element of the overall
    # matrix profile index is the time series position of the corresponding sub-profile.
    for result in results:
        for dp, querySegmentsID in result:
            #Check which of the indices have found a new minimum
            idsToUpdate = dp < mp

            #Update the Matrix Profile Index to indicate that the current index is the minimum location for the aforementioned indices
            mpIndex[idsToUpdate] = querySegmentsID[idsToUpdate]

            #Update the matrix profile to include the new minimum values (where appropriate)
            mp = np.minimum(mp, dp)

    return (mp, mpIndex)