コード例 #1
0
def analyze_pmp(ts, query, sample_pct, threshold, windows=None, n_jobs=-1):
    """
    Computes the Pan-MatrixProfile, top 3 motifs and top 3 discords for the
    provided time series and query. Additionally, plots for the PMP, motifs
    and discords is provided.

    Parameters
    ----------
    ts : array_like
        The time series to analyze.
    query : array_like
        The query to analyze.
    sample_pct : float
        A float between 0 and 1 representing how many samples to compute for
        the PMP.
    threshold : float
        A correlation threshold between 0 and 1 that is used to compute the
        upper window. Note that this is used only when the windows is None.
    windows : array_like, default None
        Integers representing the desired windows to use during the
        computation of the PMP.
    n_jobs : int, default -1 (all cpu cores)
        The number of cpu cores to use when computing the PMP.
    
    Returns
    -------
    tuple : (profile, figures)
        A tuple with the first item being the profile and the second being an
        array of matplotlib figures.

    """
    ts = core.to_np_array(ts)

    if isinstance(threshold, type(None)):
        threshold = 0.98

    # when a threshold is passed, we compute the upper window
    profile = None
    if isinstance(windows, type(None)):
        profile = maximum_subsequence(ts, threshold, include_pmp=True)

        # determine windows to be computed
        # from 8 in steps of 2 until upper w
        start = 8
        windows = range(start, profile['upper_window'] + 1)

    # compute the pmp
    profile = skimp(ts, windows=windows, sample_pct=sample_pct,
                          pmp_obj=profile)

    # extract top motifs
    profile = motifs(profile)

    # extract top discords
    profile = discords(profile)

    # plot pmp
    figures = visualize(profile)

    return (profile, figures)
コード例 #2
0
def ECG():
    ecg = mp.datasets.load('ecg-heartbeat-av')
    ts = ecg['data']
    window_size = 150
    profile = mp.compute(ts, windows=window_size)
    profile = mp.discover.motifs(profile, k=1)
    threshold = 1200
    av = \
        np.append(np.zeros(threshold),
                  np.ones(len(profile['mp']) -
                          threshold))

    profile = mp.transform.apply_av(profile, "custom", av)
    profile = mp.discover.motifs(profile, k=3, use_cmp=True, exclusion_zone=100)
    figures = mp.visualize(profile)
    figures[3].show()
コード例 #3
0
ファイル: analyze.py プロジェクト: DemianD/matrixprofile-fork
def analyze_mp_approximate(ts, query, window, sample_pct, n_jobs=-1):
    """
    Computes the exact MatrixProfile, top 3 motifs and top 3 discords for the
    provided time series and query. Additionally, the MatrixProfile, discords
    and motifs are visualized.

    Parameters
    ----------
    ts : array_like
        The time series to analyze.
    query : array_like
        The query to analyze.
    window : int
        The window size to compute the MatrixProfile.
    sample_pct : float
        A float between 0 and 1 representing how many samples to compute for
        the MP. When it is 1, it is the same as using the exact algorithm.
    n_jobs : int, default -1 (all cpu cores)
        The number of cpu cores to use when computing the MP.
    
    Returns
    -------
    tuple : (profile, figures)
        A tuple with the first item being the profile and the second being an
        array of matplotlib figures.

    """
    ts = core.to_np_array(ts)

    # compute mp
    profile = scrimp_plus_plus(ts,
                               window,
                               query=query,
                               sample_pct=sample_pct,
                               n_jobs=n_jobs)

    # extract top motifs
    profile = motifs(profile)

    # extract top discords
    profile = discords(profile)

    # plot mp
    figures = visualize(profile)

    return (profile, figures)
コード例 #4
0
ファイル: analyze.py プロジェクト: DemianD/matrixprofile-fork
def analyze_mp_exact(ts, query, window, n_jobs=-1):
    """
    Computes the exact MatrixProfile, top 3 motifs and top 3 discords for the
    provided time series and query. Additionally, the MatrixProfile, discords
    and motifs are visualized.

    Parameters
    ----------
    ts : array_like
        The time series to analyze.
    query : array_like
        The query to analyze.
    window : int
        The window size to compute the MatrixProfile.
    n_jobs : int, default -1 (all cpu cores)
        The number of cpu cores to use when computing the MP.
    
    Returns
    -------
    tuple : (profile, figures)
        A tuple with the first item being the profile and the second being an
        array of matplotlib figures.

    """
    ts = core.to_np_array(ts)

    # compute mp
    profile = mpx(ts, window, query=query, n_jobs=n_jobs)

    # extract top motifs
    profile = motifs(profile)

    # extract top discords
    profile = discords(profile)

    # plot mp
    figures = visualize(profile)

    return (profile, figures)
コード例 #5
0
def show_profile(profile, title, type):
    lst_figs = mp.visualize(profile)
    for i in range(len(lst_figs)-1):
        plt.close(lst_figs[i])
    plt.suptitle('Deaths - ' + type + ' - ' + title)
    plt.savefig('Deaths - ' + type + ' - ' + title)
コード例 #6
0
def show_profile(profile, title, type):
    lst_figs = mp.visualize(profile)
    for i in range(len(lst_figs) - 1):
        plt.close(lst_figs[i])
    plt.suptitle('Covid19 - ' + type + ' - ' + title)
    plt.savefig(graphsDir + 'Covid19 - ' + type + ' - ' + title)