How to use the pyts.utils.sax function in pyts

To help you get started, we’ve selected a few pyts 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 johannfaouzi / pyts / pyts / visualization / visualization.py View on Github external
plt.plot(ts, color='#1f77b4', **kwargs)
    for i in range(indices_len):
        plt.plot(indices[i], np.repeat(ts_paa[i], indices[i].size), 'r-')

    plt.axvline(x=indices[0][0], ls='--', linewidth=1, color='k')
    for i in range(indices_len - 1):
        plt.axvline(x=(indices[i][-1] + indices[i + 1][0]) / 2, ls='--', linewidth=1, color='k')
    plt.axvline(x=indices[indices_len - 1][-1], ls='--', linewidth=1, color='k')

    # Alphabet
    alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

    # Compute gaussian quantiles if quantiles == 'gaussian'
    if quantiles == 'gaussian':
        quantiles = scipy.stats.norm.ppf(np.linspace(0, 1, num=n_bins + 1)[1:])
        ts_sax = sax(ts_paa, n_bins, quantiles, alphabet, plot=True)
    else:
        quantiles, ts_sax = sax(ts_paa, n_bins, quantiles, alphabet, plot=True)

    for i in range(n_bins - 1):
        plt.axhline(y=quantiles[i], ls='--', lw=1, color='g')

    x_lim = ax.get_xlim()
    y_lim = ax.get_ylim()
    for i in range(indices_len):
        x_pos = (np.percentile(indices[i], [50]) - x_lim[0]) / (x_lim[1] - x_lim[0])
        y_pos = (ts_paa[i] - y_lim[0]) / (y_lim[1] - y_lim[0])
        ax.text(x_pos, y_pos, ts_sax[i],
                horizontalalignment='center', verticalalignment='bottom',
                transform=ax.transAxes, color='m', fontsize=25)

    if output_file is not None:
github johannfaouzi / pyts / pyts / visualization / visualization.py View on Github external
if n_bins < 2:
        raise ValueError("'n_bins' must be greater or equal than 2.")
    if n_bins > 52:
        raise ValueError("'n_bins' must be lower or equal than 52.")
    if quantiles not in ['gaussian', 'empirical']:
        raise ValueError("'quantiles' must be either 'gaussian' or 'empirical'.")

    # Alphabet
    alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

    # Compute gaussian quantiles if quantiles == 'gaussian'
    if quantiles == 'gaussian':
        quantiles = scipy.stats.norm.ppf(np.linspace(0, 1, num=n_bins + 1)[1:])
        ts_sax = sax(ts, n_bins, quantiles, alphabet, plot=True)
    else:
        quantiles, ts_sax = sax(ts, n_bins, quantiles, alphabet, plot=True)

    fig = plt.figure()
    ax = fig.add_subplot(111)

    plt.plot(ts, color='r', **kwargs)

    for i in range(n_bins - 1):
        plt.axhline(y=quantiles[i], ls='--', lw=1, color='g')

    if 1:
        x_lim = ax.get_xlim()
        y_lim = ax.get_ylim()
        for i in range(len(ts_sax)):
            x_pos = (i - x_lim[0]) / (x_lim[1] - x_lim[0])
            y_pos = (ts[i] - y_lim[0]) / (y_lim[1] - y_lim[0])
            ax.text(x_pos, y_pos, ts_sax[i],
github johannfaouzi / pyts / pyts / visualization / visualization.py View on Github external
plt.plot(indices[i], np.repeat(ts_paa[i], indices[i].size), 'r-')

    plt.axvline(x=indices[0][0], ls='--', linewidth=1, color='k')
    for i in range(indices_len - 1):
        plt.axvline(x=(indices[i][-1] + indices[i + 1][0]) / 2, ls='--', linewidth=1, color='k')
    plt.axvline(x=indices[indices_len - 1][-1], ls='--', linewidth=1, color='k')

    # Alphabet
    alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

    # Compute gaussian quantiles if quantiles == 'gaussian'
    if quantiles == 'gaussian':
        quantiles = scipy.stats.norm.ppf(np.linspace(0, 1, num=n_bins + 1)[1:])
        ts_sax = sax(ts_paa, n_bins, quantiles, alphabet, plot=True)
    else:
        quantiles, ts_sax = sax(ts_paa, n_bins, quantiles, alphabet, plot=True)

    for i in range(n_bins - 1):
        plt.axhline(y=quantiles[i], ls='--', lw=1, color='g')

    x_lim = ax.get_xlim()
    y_lim = ax.get_ylim()
    for i in range(indices_len):
        x_pos = (np.percentile(indices[i], [50]) - x_lim[0]) / (x_lim[1] - x_lim[0])
        y_pos = (ts_paa[i] - y_lim[0]) / (y_lim[1] - y_lim[0])
        ax.text(x_pos, y_pos, ts_sax[i],
                horizontalalignment='center', verticalalignment='bottom',
                transform=ax.transAxes, color='m', fontsize=25)

    if output_file is not None:
        plt.savefig(output_file)
github johannfaouzi / pyts / pyts / visualization / visualization.py View on Github external
if not isinstance(n_bins, int):
        raise TypeError("'n_bins' must be an integer.")
    if n_bins < 2:
        raise ValueError("'n_bins' must be greater or equal than 2.")
    if n_bins > 52:
        raise ValueError("'n_bins' must be lower or equal than 52.")
    if quantiles not in ['gaussian', 'empirical']:
        raise ValueError("'quantiles' must be either 'gaussian' or 'empirical'.")

    # Alphabet
    alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

    # Compute gaussian quantiles if quantiles == 'gaussian'
    if quantiles == 'gaussian':
        quantiles = scipy.stats.norm.ppf(np.linspace(0, 1, num=n_bins + 1)[1:])
        ts_sax = sax(ts, n_bins, quantiles, alphabet, plot=True)
    else:
        quantiles, ts_sax = sax(ts, n_bins, quantiles, alphabet, plot=True)

    fig = plt.figure()
    ax = fig.add_subplot(111)

    plt.plot(ts, color='r', **kwargs)

    for i in range(n_bins - 1):
        plt.axhline(y=quantiles[i], ls='--', lw=1, color='g')

    if 1:
        x_lim = ax.get_xlim()
        y_lim = ax.get_ylim()
        for i in range(len(ts_sax)):
            x_pos = (i - x_lim[0]) / (x_lim[1] - x_lim[0])