首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >导入错误:没有名为“mstamp_stomp”的模块

导入错误:没有名为“mstamp_stomp”的模块
EN

Stack Overflow用户
提问于 2019-02-26 22:12:43
回答 1查看 776关注 0票数 0

我正在尝试从git存储库https://github.com/mcyeh/mstamp/tree/master/Python中运行https://github.com/mcyeh/mstamp/tree/master/Python。这是论文矩阵轮廓VI:有意义的多维模体发现的源代码。我已经附上了下面的代码。

代码语言:javascript
复制
# -*- coding: utf-8 -*-
"""
@author: Michael Yeh
C.-C. M. Yeh, N. Kavantzas, and E. Keogh, "Matrix Profile VI: Meaningful
Multidimensional Motif Discovery," IEEE ICDM 2017.
https://sites.google.com/view/mstamp/
http://www.cs.ucr.edu/~eamonn/MatrixProfile.html
"""

import scipy.io as sio
import matplotlib.pyplot as plt
from mstamp_stomp import mstamp as mstamp_stomp
from mstamp_stamp import mstamp as mstamp_stamp


def plot_motifs(matrix_profile, dimensionality=1):
    motif_at = matrix_profile[dimensionality - 1, :].argsort()[:2]

    plt.figure(figsize=(14, 7))
    for i in range(3):
        plt.subplot(4, 1, i + 1)
        plt.plot(data.T[i, :])
        plt.title('$T_{}$'.format(i + 1))
        for m in motif_at:
            plt.plot(range(m, m + sub_len), data.T[i, :][m:m + sub_len], c='r')
        plt.xlim((0, matrix_profile.shape[1]))

    plt.subplot(414)
    plt.title('{}-dimensional Matrix Profile'.format(dimensionality))
    plt.plot(matrix_profile[dimensionality - 1, :])
    for m in motif_at:
        plt.axvline(m, c='r')
    plt.xlim((0, matrix_profile.shape[1]))
    plt.tight_layout()


if __name__ == '__main__':
    mat = sio.loadmat('toy_data.mat')
    data = mat['data']
    sub_len = mat['sub_len'][0][0]

    # using the stomp based method to compute the multidimensional matrix
    # profile
    mat_pro_1, pro_idx_1 = mstamp_stomp(data.T, sub_len,
                                        return_dimension=False)

    # plot the matrix profile as image
    plt.figure()
    plt.title('Matrix Profile (STOMP)')
    plt.imshow(mat_pro_1, extent=[0, 1, 0, 1])

    # using the stamp based method to compute the multidimensional matrix
    # profile
    mat_pro_2, pro_idx_2 = mstamp_stamp(data.T, sub_len,
                                        return_dimension=False)

    # plot the matrix profile as image
    plt.figure()
    plt.title('Matrix Profile (STAMP)')
    plt.imshow(mat_pro_2, extent=[0, 1, 0, 1])

    plot_motifs(mat_pro_2)

    # the function can also be used to compute the 1D matrix profile
    mat_pro_3, _ = mstamp_stomp(data[:, 1].T, sub_len,
                                return_dimension=False)
    plt.figure()
    plt.plot(mat_pro_3[0, :])

    mat_pro_4, _ = mstamp_stamp(data[:, 1].T, sub_len,
                                return_dimension=False)
    plt.figure()
    plt.plot(mat_pro_4[0, :])

    plt.show()
EN

回答 1

Stack Overflow用户

发布于 2019-02-27 02:14:08

导入错误:没有名为“mstamp_stomp”的模块

这反映了搜索路径问题。您将希望在包含源代码的目录中使用chdir,并且在执行代码之前,您还希望在路径中有.点:

代码语言:javascript
复制
$ cd mstamp/Python
$ export PYTHONPATH=.
$ python demo.py

您可以使用此代码片段来调试以下问题:

代码语言:javascript
复制
import pprint
import sys
pprint.pprint(sys.path)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54895017

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档