GithubHelp home page GithubHelp logo

forrestbao / pyeeg Goto Github PK

View Code? Open in Web Editor NEW
234.0 12.0 86.0 119 KB

Python + EEG/MEG = PyEEG

License: GNU General Public License v3.0

Python 100.00%
python series meg python-eeg eeg physiology

pyeeg's Introduction

pyeeg

Python + EEG/MEG = PyEEG

Welcome to PyEEG! This is a Python module with many functions for time series analysis, including brain physiological signals. Feel free to try it with any time series: biomedical, financial, etc.

Installation

Via Git

Clone the repo via HTTPS:

$ git clone https://github.com/forrestbao/pyeeg.git

This will create a new directory, pyeeg with the repo in it. Change into that directory and execute setup.py:

$ cd pyeeg
$ python setup.py install

To install under your home directory, try:

$ python setup.py install --user

Via pip

pip supports installing from a GitHub repo. Follow the instructions for cloning.

Testing

Run the test suite contained in tests/.

$ python setup.py test

Cite

If you use PyEEG in your research, please cite this paper: PyEEG: An Open Source Python Module for EEG/MEG Feature Extraction, Forrest Sheng Bao, Xin Liu, and Christina Zhang, Computational Intelligence and Neuroscience, volume 2011, Article ID 406391

pyeeg's People

Contributors

bergantine avatar bnaul avatar borzou avatar forrestbao avatar himkt avatar mattja avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyeeg's Issues

Result of the hurst exponent are wrong

from numpy import cumsum, log, polyfit, sqrt, std, subtract
from numpy.random import randn

def hurst(ts):
    """Returns the Hurst Exponent of the time series vector ts"""
    # Create the range of lag values
    lags = range(2, 100)

    # Calculate the array of the variances of the lagged differences
    tau = [sqrt(std(subtract(ts[lag:], ts[:-lag]))) for lag in lags]

    # Use a linear fit to estimate the Hurst Exponent
    poly = polyfit(log(lags), log(tau), 1)

    # Return the Hurst exponent from the polyfit output
    return poly[0]*2.0

# Create a Gometric Brownian Motion, Mean-Reverting and Trending Series
gbm = log(cumsum(randn(100000))+1000)
mr = log(randn(100000)+1000)
tr = log(cumsum(randn(100000)+1)+1000)

# Output the Hurst Exponent for each of the above series
# and the price of Google (the Adjusted Close price) for 
# the ADF test given above in the article
print "Hurst(GBM):   %s" % hurst(gbm)
print "Hurst(MR):    %s" % hurst(mr)
print "Hurst(TR):    %s" % hurst(tr)

I compared with the results of pyeeg.hurst and they are quite different.
I you want I can do a pull request to update the method

TypeError brought by numpy.floor()

Hi, Thanks for building this lib !

I found the same issue as #22 and #21, and I do the same fix manually myself.

May I ask a reason for not merging them into master? That is only a tiny problem brought by numpy version and should be straight forward to review.

question

Hi, first thanks a lot for this valuable module that you provide and make it available for us
secondary, would you please help me by answering my question.
this is my question:
in the code the input of function is x
such in calculating entropy in function one of the input or parameter as you explain is "x" and was introduced time series, a question arise in my brain :what's your meaning of this statement " x:time series"
a: your meaning is the EEG signal that export to ascii format (numerical format)
b: we should use time series analysis and make a time series from the EEG signal

beside my evaluation EEG signal can be considered as a time series when it export to ascii format(numerical format)
Would you please help me? it is so emergency and vital for me and I should to solve this problem as soon as possible

Error when installing

Hi, i`m using python 3.5 and there is error when installing under home directory. Using GIT Bash and python 3.5. Thanks

name erron

line 500 name not is "Y = Embed_seq(X, Tau, DE)"
fix Y = embed_seq(X, Tau, DE)

issue after running $ python setup.py test

Seeing below issue. Has anybody seen this issue before with largest_lyauponov_exponent.py after running "$ python setup.py test" and would be able to share a solution if one was found? I haven't been able to figure it out..

largest_lyauponov_exponent.py:119: FutureWarning: rcond parameter will change to the default of machine precision times max(M, N) where M and N are the input matrix dimensions.
To use the future default and silence this warning we advise to pass rcond=None, to keep using the old, explicitly pass rcond=-1.
[m, c] = numpy.linalg.lstsq(X, mean_d)[0]
FAIL
test_permutation_entropy (tests.test_permutation_entropy.PermutationEntropyTests.test_permutation_entropy) ... ok
test_sampen_against_original_c_test_data (tests.test_sampen.SampEnTests.test_sampen_against_original_c_test_data)
Use test data from ... ok
test_sampen_against_predictable_sequence (tests.test_sampen.SampEnTests.test_sampen_against_predictable_sequence) ... ok

======================================================================
FAIL: test_largest_lyauponov_exponent (tests.test_largest_lyauponov_exponent.LLETests.test_largest_lyauponov_exponent)

\pyeeg\tests\test_largest_lyauponov_exponent.py", line 11, in test_largest_lyauponov_exponent
self.assertAlmostEqual(
AssertionError: nan != 0.18771136179353307 within 12 places (nan difference)


Ran 8 tests in 1.857s

FAILED (failures=1)
Test failed: <unittest.runner.TextTestResult run=8 errors=0 failures=1>
error: Test failed: <unittest.runner.TextTestResult run=8 errors=0 failures=1>

enhance hfd

def hfd(X, Kmax):
    """ Compute Hjorth Fractal Dimension of a time series X, kmax
     is an HFD parameter
    """
    **try:**
        L = []
        x = []
        N = len(X)
        for k in range(1, Kmax):
            Lk = []
            for m in range(0, k):
                Lmk = 0
                for i in range(1, int(numpy.floor((N - m) / k))):
                    Lmk += abs(X[m + i * k] - X[m + i * k - k])
                Lmk = Lmk * (N - 1) / numpy.floor((N - m) / float(k)) / k
                Lk.append(Lmk)
            **if numpy.mean(Lk) != 0:
                L.append(numpy.log(numpy.mean(Lk)))
                x.append([numpy.log(float(1) / k), 1])
                (p, r1, r2, s) = numpy.linalg.lstsq(x, L)
                return p[0]
            else:
                return 0**
    **except Exception as e:
        return 0**

Information Based Similarity run error

When I try to run the example code for Information Based Similarity it returns:

information_based_similarity(test1, test2, 8)
Traceback (most recent call last):

File "", line 1, in
information_based_similarity(test1, test2, 8)

File "/home/tfv21/anaconda3/lib/python3.6/site-packages/pyeeg/init.py", line 955, in information_based_similarity
Wm.append(embed_seq(SymbolicSeq[0], 1, n).tolist())

File "/home/tfv21/anaconda3/lib/python3.6/site-packages/pyeeg/init.py", line 161, in embed_seq
shape = (X.size - Tau * (D - 1), D)

AttributeError: 'list' object has no attribute 'size'

I tried changing X.size to len(X), but that threw the same error in the same function (list object has no attribute 'itemsize.'

Please advise.

Modification in Hjorth mobility and complexity

Hello, first thank you for this module!
For the calculation of Hjorth mobility and complexity, I got NaN returned.
It was because I was working with big numbers, TP has became negative and as a sqrt function is applied later on, the calculation was impossible.
I have solved the problem by adding "dtype = object" when declaring numpy array so I have enough space to store those numbers.
I hope it will help some poeple running this code!

About the naming conventions in pyeeg

Hi,

Thanks for this module and I am going to use it in my project.

I think there should be a pyeeg.py in the pyeeg/ folder, and write a new __init__.py file to manually import all the relevant module. like

__all__ = ['hurst', 'lle']

from .pyeeg import hurst, lle

it's more python and follows the >3.3 standard

testing not working when installing

Hi, I received the following error when testing after installation:

$python setup.py test

running test
running egg_info
writing pyeeg.egg-info/PKG-INFO
writing dependency_links to pyeeg.egg-info/dependency_links.txt
writing requirements to pyeeg.egg-info/requires.txt
writing top-level names to pyeeg.egg-info/top_level.txt
reading manifest file 'pyeeg.egg-info/SOURCES.txt'
writing manifest file 'pyeeg.egg-info/SOURCES.txt'
running build_ext
test_embedded_sequence_1_4 (tests.test_embedded_sequence.EmbeddedSequenceTests) ... ok
test_embedded_sequence_2_3 (tests.test_embedded_sequence.EmbeddedSequenceTests) ... ok
test_embedded_sequence_4_1 (tests.test_embedded_sequence.EmbeddedSequenceTests) ... ok
test_information_based_similarity (tests.test_information_based_similarity.InformationBasedSimilarityTests) ... ok
test_largest_lyauponov_exponent (tests.test_largest_lyauponov_exponent.LLETests) ... ERROR
test_permutation_entropy (tests.test_permutation_entropy.PermutationEntropyTests) ... ok
test_sampen_against_original_c_test_data (tests.test_sampen.SampEnTests)
Use test data from ... ok
test_sampen_against_predictable_sequence (tests.test_sampen.SampEnTests) ... ok

======================================================================
ERROR: test_largest_lyauponov_exponent (tests.test_largest_lyauponov_exponent.LLETests)

Traceback (most recent call last):
File "/Users/ross/Desktop/Documents/Research/contrasting_6_meditation_practices_EEG/pyeeg/tests/test_largest_lyauponov_exponent.py", line 12, in test_largest_lyauponov_exponent
LLE(data, 2, 4, 1, 1),
File "/Users/ross/Desktop/Documents/Research/contrasting_6_meditation_practices_EEG/pyeeg/pyeeg/largest_lyauponov_exponent.py", line 75, in LLE
from embedded_sequence import embed_seq
ModuleNotFoundError: No module named 'embedded_sequence'


Ran 8 tests in 3.996s

FAILED (errors=1)
Test failed: <unittest.runner.TextTestResult run=8 errors=1 failures=0>
error: Test failed: <unittest.runner.TextTestResult run=8 errors=1 failures=0>

NameError: global name 'np' is not defined

I have installed pyeeg using pip. This is my line in requirements.txt:

-e git+https://github.com/forrestbao/pyeeg.git#egg=pyeeg

When I use pyeeg.ap_entropy I am encountering the following error:

NameError: global name 'np' is not defined

I have numpy installed, I'm importing it as np, and it works fine.
Do you have any idea what this might be?

Thanks!

About pull request to this repository

Hi,

I issued a pull request
to
https://github.com/jbergantine/pyeeg
from
https://github.com/mfeit/pyeeg

it is possible to merge the pull request to this repository or do I need to create a new pull request ?

NaN values

Maybe this is a question out of pyeeg's scope...
Approximate entropy is a new concept to me and I'm having several NaN values in my data.

audio_ap_entropy_7days  activity_ap_entropy_7days
1   NaN NaN
2   -0.085044   -0.085044
4   -0.096893   -0.096893
5   -0.088628   -0.088628
7   -0.110994   -0.110994
8   NaN NaN
9   -0.086203   -0.086203
10  -0.085044   -0.085044
12  -0.085044   -0.085044
14  NaN NaN
15  NaN NaN
16  -0.088628   -0.088628
17  NaN NaN
18  NaN NaN
19  NaN NaN
22  NaN NaN
24  -0.169545   -0.169545
25  NaN NaN
27  -0.085044   -0.085044
30  NaN NaN
32  NaN NaN
33  NaN NaN
41  NaN NaN
43  NaN NaN
46  NaN NaN
49  -0.085044   -0.085044
52  NaN NaN
54  NaN NaN
57  -0.085044   -0.085044
59  -0.085044   -0.085044

Is this a normal behavior in approximate entropy, or do you think there's something wrong?

Luis

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.