├── .gitignore ├── LICENSE.txt ├── README.md ├── pyeeg ├── __init__.py ├── detrended_fluctuation_analysis.py ├── embedded_sequence.py ├── entropy.py ├── fisher_info.py ├── fractal_dimension.py ├── hjorth_mobility_complexity.py ├── hurst.py ├── information_based_similarity.py ├── largest_lyauponov_exponent.py └── spectrum.py ├── setup.cfg ├── setup.py └── tests ├── __init__.py ├── demo_data └── sampentest.txt ├── test_embedded_sequence.py ├── test_information_based_similarity.py ├── test_largest_lyauponov_exponent.py ├── test_permutation_entropy.py └── test_sampen.py /.gitignore: -------------------------------------------------------------------------------- 1 | *.py[cod] 2 | 3 | # C extensions 4 | *.so 5 | 6 | # Packages 7 | *.egg 8 | *.egg-info 9 | .Python 10 | dist 11 | build 12 | eggs 13 | include 14 | parts 15 | bin 16 | var 17 | sdist 18 | develop-eggs 19 | .installed.cfg 20 | lib 21 | lib64 22 | __pycache__ 23 | 24 | # Installer logs 25 | pip-log.txt 26 | 27 | # Unit test / coverage reports 28 | .coverage 29 | .tox 30 | nosetests.xml 31 | 32 | # Translations 33 | *.mo 34 | 35 | # Mr Developer 36 | .mr.developer.cfg 37 | .project 38 | .pydevproject 39 | .tox/ 40 | .eggs/ 41 | *.egg-info 42 | build/ 43 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | pyeeg 2 | ===== 3 | 4 | Python + EEG/MEG = PyEEG 5 | 6 | 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. 7 | 8 | Installation 9 | ------------ 10 | 11 | ### Via Git 12 | 13 | Clone the repo via HTTPS: 14 | 15 | ```sh 16 | $ git clone https://github.com/forrestbao/pyeeg.git 17 | ``` 18 | 19 | This will create a new directory, `pyeeg` with the repo in it. Change into that directory and execute `setup.py`: 20 | 21 | ```sh 22 | $ cd pyeeg 23 | $ python setup.py install 24 | ``` 25 | 26 | To install under your home directory, try: 27 | ```sh 28 | $ python setup.py install --user 29 | ``` 30 | 31 | ### Via pip 32 | 33 | pip supports installing from a GitHub repo. Follow the [instructions for cloning](https://pip.pypa.io/en/latest/reference/pip_install.html#git). 34 | 35 | Testing 36 | ------- 37 | 38 | Run the test suite contained in `tests/`. 39 | 40 | ```sh 41 | $ python setup.py test 42 | ``` 43 | 44 | Cite 45 | ------ 46 | If you use PyEEG in your research, please cite this paper: 47 | [PyEEG: An Open Source Python Module for EEG/MEG Feature Extraction](https://www.hindawi.com/journals/cin/2011/406391/), Forrest Sheng Bao, Xin Liu, and Christina Zhang, Computational Intelligence and Neuroscience, volume 2011, Article ID 406391 48 | -------------------------------------------------------------------------------- /pyeeg/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=UTF-8 2 | 3 | """Copyleft 2010-2018 Forrest Sheng Bao http://fsbao.net 4 | Copyleft 2010 Xin Liu 5 | Copyleft 2014-2015 Borzou Alipour Fard 6 | 7 | PyEEG, a Python module to extract EEG feature. 8 | 9 | Project homepage: http://pyeeg.org 10 | 11 | **Data structure** 12 | 13 | PyEEG only uses standard Python and numpy data structures, 14 | so you need to import numpy before using it. 15 | For numpy, please visit http://numpy.scipy.org 16 | 17 | **Naming convention** 18 | 19 | I follow "Style Guide for Python Code" to code my program 20 | http://www.python.org/dev/peps/pep-0008/ 21 | 22 | -------------------------------------------------- 23 | 24 | """ 25 | 26 | from .entropy import ap_entropy, permutation_entropy, samp_entropy, spectral_entropy, svd_entropy 27 | from .spectrum import bin_power 28 | from .detrended_fluctuation_analysis import dfa 29 | from .embedded_sequence import embed_seq 30 | from .fisher_info import fisher_info 31 | from .fractal_dimension import hfd, pfd 32 | from .hjorth_mobility_complexity import hjorth 33 | from .hurst import hurst 34 | from .information_based_similarity import information_based_similarity 35 | from .largest_lyauponov_exponent import LLE 36 | -------------------------------------------------------------------------------- /pyeeg/detrended_fluctuation_analysis.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | 3 | import numpy 4 | 5 | 6 | def dfa(X, Ave=None, L=None): 7 | """Compute Detrended Fluctuation Analysis from a time series X and length of 8 | boxes L. 9 | 10 | The first step to compute DFA is to integrate the signal. Let original 11 | series be X= [x(1), x(2), ..., x(N)]. 12 | 13 | The integrated signal Y = [y(1), y(2), ..., y(N)] is obtained as follows 14 | y(k) = \sum_{i=1}^{k}{x(i)-Ave} where Ave is the mean of X. 15 | 16 | The second step is to partition/slice/segment the integrated sequence Y 17 | into boxes. At least two boxes are needed for computing DFA. Box sizes are 18 | specified by the L argument of this function. By default, it is from 1/5 of 19 | signal length to one (x-5)-th of the signal length, where x is the nearest 20 | power of 2 from the length of the signal, i.e., 1/16, 1/32, 1/64, 1/128, 21 | ... 22 | 23 | In each box, a linear least square fitting is employed on data in the box. 24 | Denote the series on fitted line as Yn. Its k-th elements, yn(k), 25 | corresponds to y(k). 26 | 27 | For fitting in each box, there is a residue, the sum of squares of all 28 | offsets, difference between actual points and points on fitted line. 29 | 30 | F(n) denotes the square root of average total residue in all boxes when box 31 | length is n, thus 32 | Total_Residue = \sum_{k=1}^{N}{(y(k)-yn(k))} 33 | F(n) = \sqrt(Total_Residue/N) 34 | 35 | The computing to F(n) is carried out for every box length n. Therefore, a 36 | relationship between n and F(n) can be obtained. In general, F(n) increases 37 | when n increases. 38 | 39 | Finally, the relationship between F(n) and n is analyzed. A least square 40 | fitting is performed between log(F(n)) and log(n). The slope of the fitting 41 | line is the DFA value, denoted as Alpha. To white noise, Alpha should be 42 | 0.5. Higher level of signal complexity is related to higher Alpha. 43 | 44 | Parameters 45 | ---------- 46 | 47 | X: 48 | 1-D Python list or numpy array 49 | a time series 50 | 51 | Ave: 52 | integer, optional 53 | The average value of the time series 54 | 55 | L: 56 | 1-D Python list of integers 57 | A list of box size, integers in ascending order 58 | 59 | Returns 60 | ------- 61 | 62 | Alpha: 63 | integer 64 | the result of DFA analysis, thus the slope of fitting line of log(F(n)) 65 | vs. log(n). where n is the 66 | 67 | Examples 68 | -------- 69 | >>> import pyeeg 70 | >>> numpy.random.seed(2018) 71 | >>> print(pyeeg.dfa(numpy.random.randn(4096))) 72 | 0.5121794335479618 73 | 74 | Reference 75 | --------- 76 | Peng C-K, Havlin S, Stanley HE, Goldberger AL. Quantification of scaling 77 | exponents and crossover phenomena in nonstationary heartbeat time series. 78 | _Chaos_ 1995;5:82-87 79 | 80 | Notes 81 | ----- 82 | 83 | This value depends on the box sizes very much. When the input is a white 84 | noise, this value should be 0.5. But, some choices on box sizes can lead to 85 | the value lower or higher than 0.5, e.g. 0.38 or 0.58. 86 | 87 | Based on many test, I set the box sizes from 1/5 of signal length to one 88 | (x-5)-th of the signal length, where x is the nearest power of 2 from the 89 | length of the signal, i.e., 1/16, 1/32, 1/64, 1/128, ... 90 | 91 | You may generate a list of box sizes and pass in such a list as a 92 | parameter. 93 | 94 | """ 95 | 96 | X = numpy.array(X) 97 | 98 | if Ave is None: 99 | Ave = numpy.mean(X) 100 | 101 | Y = numpy.cumsum(X) 102 | Y -= Ave 103 | 104 | if L is None: 105 | L = numpy.floor(len(X) * 1 / ( 106 | 2 ** numpy.array(list(range(4, int(numpy.log2(len(X))) - 4)))) 107 | ) 108 | 109 | F = numpy.zeros(len(L)) # F(n) of different given box length n 110 | 111 | for i in range(0, len(L)): 112 | n = int(L[i]) # for each box length L[i] 113 | if n == 0: 114 | print("time series is too short while the box length is too big") 115 | print("abort") 116 | exit() 117 | for j in range(0, len(X), n): # for each box 118 | if j + n < len(X): 119 | c = list(range(j, j + n)) 120 | # coordinates of time in the box 121 | c = numpy.vstack([c, numpy.ones(n)]).T 122 | # the value of data in the box 123 | y = Y[j:j + n] 124 | # add residue in this box 125 | F[i] += numpy.linalg.lstsq(c, y)[1] 126 | F[i] /= ((len(X) / n) * n) 127 | F = numpy.sqrt(F) 128 | 129 | Alpha = numpy.linalg.lstsq(numpy.vstack( 130 | [numpy.log(L), numpy.ones(len(L))] 131 | ).T, numpy.log(F))[0][0] 132 | 133 | return Alpha 134 | 135 | 136 | 137 | if __name__ == "__main__": 138 | import doctest 139 | doctest.testmod(verbose=True) 140 | -------------------------------------------------------------------------------- /pyeeg/embedded_sequence.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | 3 | 4 | def embed_seq(time_series, tau, embedding_dimension): 5 | """Build a set of embedding sequences from given time series `time_series` 6 | with lag `tau` and embedding dimension `embedding_dimension`. 7 | 8 | Let time_series = [x(1), x(2), ... , x(N)], then for each i such that 9 | 1 < i < N - (embedding_dimension - 1) * tau, 10 | we build an embedding sequence, 11 | Y(i) = [x(i), x(i + tau), ... , x(i + (embedding_dimension - 1) * tau)]. 12 | 13 | All embedding sequences are placed in a matrix Y. 14 | 15 | Parameters 16 | ---------- 17 | 18 | time_series 19 | list or numpy.ndarray 20 | 21 | a time series 22 | 23 | tau 24 | integer 25 | 26 | the lag or delay when building embedding sequence 27 | 28 | embedding_dimension 29 | integer 30 | 31 | the embedding dimension 32 | 33 | Returns 34 | ------- 35 | 36 | Y 37 | 2-embedding_dimension list 38 | 39 | embedding matrix built 40 | 41 | Examples 42 | --------------- 43 | >>> import pyeeg 44 | >>> a=range(0,9) 45 | >>> pyeeg.embed_seq(a,1,4) 46 | array([[0, 1, 2, 3], 47 | [1, 2, 3, 4], 48 | [2, 3, 4, 5], 49 | [3, 4, 5, 6], 50 | [4, 5, 6, 7], 51 | [5, 6, 7, 8]]) 52 | >>> pyeeg.embed_seq(a,2,3) 53 | array([[0, 2, 4], 54 | [1, 3, 5], 55 | [2, 4, 6], 56 | [3, 5, 7], 57 | [4, 6, 8]]) 58 | >>> pyeeg.embed_seq(a,4,1) 59 | array([[0], 60 | [1], 61 | [2], 62 | [3], 63 | [4], 64 | [5], 65 | [6], 66 | [7], 67 | [8]]) 68 | 69 | """ 70 | if not type(time_series) == numpy.ndarray: 71 | typed_time_series = numpy.asarray(time_series) 72 | else: 73 | typed_time_series = time_series 74 | 75 | shape = ( 76 | typed_time_series.size - tau * (embedding_dimension - 1), 77 | embedding_dimension 78 | ) 79 | 80 | strides = (typed_time_series.itemsize, tau * typed_time_series.itemsize) 81 | 82 | return numpy.lib.stride_tricks.as_strided( 83 | typed_time_series, 84 | shape=shape, 85 | strides=strides 86 | ) 87 | 88 | if __name__ == "__main__": 89 | import doctest 90 | doctest.testmod(verbose=True) 91 | -------------------------------------------------------------------------------- /pyeeg/entropy.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | from .embedded_sequence import embed_seq 3 | 4 | 5 | def ap_entropy(X, M, R): 6 | """Computer approximate entropy (ApEN) of series X, specified by M and R. 7 | 8 | Suppose given time series is X = [x(1), x(2), ... , x(N)]. We first build 9 | embedding matrix Em, of dimension (N-M+1)-by-M, such that the i-th row of 10 | Em is x(i),x(i+1), ... , x(i+M-1). Hence, the embedding lag and dimension 11 | are 1 and M-1 respectively. Such a matrix can be built by calling pyeeg 12 | function as Em = embed_seq(X, 1, M). Then we build matrix Emp, whose only 13 | difference with Em is that the length of each embedding sequence is M + 1 14 | 15 | Denote the i-th and j-th row of Em as Em[i] and Em[j]. Their k-th elements 16 | are Em[i][k] and Em[j][k] respectively. The distance between Em[i] and 17 | Em[j] is defined as 1) the maximum difference of their corresponding scalar 18 | components, thus, max(Em[i]-Em[j]), or 2) Euclidean distance. We say two 19 | 1-D vectors Em[i] and Em[j] *match* in *tolerance* R, if the distance 20 | between them is no greater than R, thus, max(Em[i]-Em[j]) <= R. Mostly, the 21 | value of R is defined as 20% - 30% of standard deviation of X. 22 | 23 | Pick Em[i] as a template, for all j such that 0 < j < N - M + 1, we can 24 | check whether Em[j] matches with Em[i]. Denote the number of Em[j], 25 | which is in the range of Em[i], as k[i], which is the i-th element of the 26 | vector k. The probability that a random row in Em matches Em[i] is 27 | \simga_1^{N-M+1} k[i] / (N - M + 1), thus sum(k)/ (N - M + 1), 28 | denoted as Cm[i]. 29 | 30 | We repeat the same process on Emp and obtained Cmp[i], but here 0>> import pyeeg 143 | >>> x = [1,2,4,5,12,3,4,5] 144 | >>> pyeeg.permutation_entropy(x,5,1) 145 | 2.0 146 | 147 | """ 148 | 149 | PeSeq = [] 150 | Em = embed_seq(x, tau, n) 151 | 152 | for i in range(0, len(Em)): 153 | r = [] 154 | z = [] 155 | 156 | for j in range(0, len(Em[i])): 157 | z.append(Em[i][j]) 158 | 159 | for j in range(0, len(Em[i])): 160 | z.sort() 161 | r.append(z.index(Em[i][j])) 162 | z[z.index(Em[i][j])] = -1 163 | 164 | PeSeq.append(r) 165 | 166 | RankMat = [] 167 | 168 | while len(PeSeq) > 0: 169 | RankMat.append(PeSeq.count(PeSeq[0])) 170 | x = PeSeq[0] 171 | for j in range(0, PeSeq.count(PeSeq[0])): 172 | PeSeq.pop(PeSeq.index(x)) 173 | 174 | RankMat = numpy.array(RankMat) 175 | RankMat = numpy.true_divide(RankMat, RankMat.sum()) 176 | EntropyMat = numpy.multiply(numpy.log2(RankMat), RankMat) 177 | PE = -1 * EntropyMat.sum() 178 | 179 | return PE 180 | 181 | def spectral_entropy(X, Band, Fs, Power_Ratio=None): 182 | """Compute spectral entropy of a time series from either two cases below: 183 | 1. X, the time series (default) 184 | 2. Power_Ratio, a list of normalized signal power in a set of frequency 185 | bins defined in Band (if Power_Ratio is provided, recommended to speed up) 186 | 187 | In case 1, Power_Ratio is computed by bin_power() function. 188 | 189 | Notes 190 | ----- 191 | To speed up, it is recommended to compute Power_Ratio before calling this 192 | function because it may also be used by other functions whereas computing 193 | it here again will slow down. 194 | 195 | Parameters 196 | ---------- 197 | 198 | Band 199 | list 200 | 201 | boundary frequencies (in Hz) of bins. They can be unequal bins, e.g. 202 | [0.5,4,7,12,30] which are delta, theta, alpha and beta respectively. 203 | You can also use range() function of Python to generate equal bins and 204 | pass the generated list to this function. 205 | 206 | Each element of Band is a physical frequency and shall not exceed the 207 | Nyquist frequency, i.e., half of sampling frequency. 208 | 209 | X 210 | list 211 | 212 | a 1-D real time series. 213 | 214 | Fs 215 | integer 216 | 217 | the sampling rate in physical frequency 218 | 219 | Returns 220 | ------- 221 | 222 | As indicated in return line 223 | 224 | See Also 225 | -------- 226 | bin_power: pyeeg function that computes spectral power in frequency bins 227 | 228 | """ 229 | 230 | if Power_Ratio is None: 231 | Power, Power_Ratio = bin_power(X, Band, Fs) 232 | 233 | Spectral_Entropy = 0 234 | for i in range(0, len(Power_Ratio) - 1): 235 | Spectral_Entropy += Power_Ratio[i] * numpy.log(Power_Ratio[i]) 236 | Spectral_Entropy /= numpy.log( 237 | len(Power_Ratio) 238 | ) # to save time, minus one is omitted 239 | return -1 * Spectral_Entropy 240 | 241 | 242 | def svd_entropy(X, Tau, DE, W=None): 243 | """Compute SVD Entropy from either two cases below: 244 | 1. a time series X, with lag tau and embedding dimension dE (default) 245 | 2. a list, W, of normalized singular values of a matrix (if W is provided, 246 | recommend to speed up.) 247 | 248 | If W is None, the function will do as follows to prepare singular spectrum: 249 | 250 | First, computer an embedding matrix from X, Tau and DE using pyeeg 251 | function embed_seq(): 252 | M = embed_seq(X, Tau, DE) 253 | 254 | Second, use scipy.linalg function svd to decompose the embedding matrix 255 | M and obtain a list of singular values: 256 | W = svd(M, compute_uv=0) 257 | 258 | At last, normalize W: 259 | W /= sum(W) 260 | 261 | Notes 262 | ------------- 263 | 264 | To speed up, it is recommended to compute W before calling this function 265 | because W may also be used by other functions whereas computing it here 266 | again will slow down. 267 | """ 268 | 269 | if W is None: 270 | Y = embed_seq(X, Tau, DE) 271 | W = numpy.linalg.svd(Y, compute_uv=0) 272 | W /= sum(W) # normalize singular values 273 | 274 | return -1 * sum(W * numpy.log(W)) 275 | 276 | def samp_entropy(X, M, R): 277 | """Computer sample entropy (SampEn) of series X, specified by M and R. 278 | SampEn is very close to ApEn. 279 | 280 | Suppose given time series is X = [x(1), x(2), ... , x(N)]. We first build 281 | embedding matrix Em, of dimension (N-M+1)-by-M, such that the i-th row of 282 | Em is x(i),x(i+1), ... , x(i+M-1). Hence, the embedding lag and dimension 283 | are 1 and M-1 respectively. Such a matrix can be built by calling pyeeg 284 | function as Em = embed_seq(X, 1, M). Then we build matrix Emp, whose only 285 | difference with Em is that the length of each embedding sequence is M + 1 286 | 287 | Denote the i-th and j-th row of Em as Em[i] and Em[j]. Their k-th elements 288 | are Em[i][k] and Em[j][k] respectively. The distance between Em[i] and 289 | Em[j] is defined as 1) the maximum difference of their corresponding scalar 290 | components, thus, max(Em[i]-Em[j]), or 2) Euclidean distance. We say two 291 | 1-D vectors Em[i] and Em[j] *match* in *tolerance* R, if the distance 292 | between them is no greater than R, thus, max(Em[i]-Em[j]) <= R. Mostly, the 293 | value of R is defined as 20% - 30% of standard deviation of X. 294 | 295 | Pick Em[i] as a template, for all j such that 0 < j < N - M , we can 296 | check whether Em[j] matches with Em[i]. Denote the number of Em[j], 297 | which is in the range of Em[i], as k[i], which is the i-th element of the 298 | vector k. 299 | 300 | We repeat the same process on Emp and obtained Cmp[i], 0 < i < N - M. 301 | The SampEn is defined as log(sum(Cm)/sum(Cmp)) 302 | 303 | References 304 | ---------- 305 | Costa M, Goldberger AL, Peng C-K, Multiscale entropy analysis of biological 306 | signals, Physical Review E, 71:021906, 2005 307 | 308 | See also 309 | -------- 310 | ap_entropy: approximate entropy of a time series 311 | """ 312 | 313 | N = len(X) 314 | 315 | Em = embed_seq(X, 1, M) 316 | A = numpy.tile(Em, (len(Em), 1, 1)) 317 | B = numpy.transpose(A, [1, 0, 2]) 318 | D = numpy.abs(A - B) # D[i,j,k] = |Em[i][k] - Em[j][k]| 319 | InRange = numpy.max(D, axis=2) <= R 320 | numpy.fill_diagonal(InRange, 0) # Don't count self-matches 321 | 322 | Cm = InRange.sum(axis=0) # Probability that random M-sequences are in range 323 | Dp = numpy.abs( 324 | numpy.tile(X[M:], (N - M, 1)) - numpy.tile(X[M:], (N - M, 1)).T 325 | ) 326 | 327 | Cmp = numpy.logical_and(Dp <= R, InRange[:-1, :-1]).sum(axis=0) 328 | 329 | # Avoid taking log(0) 330 | Samp_En = numpy.log(numpy.sum(Cm + 1e-100) / numpy.sum(Cmp + 1e-100)) 331 | 332 | return Samp_En 333 | -------------------------------------------------------------------------------- /pyeeg/fisher_info.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | from .embedded_sequence import embed_seq 3 | 4 | 5 | def fisher_info(X, Tau, DE, W=None): 6 | """Compute SVD Entropy from either two cases below: 7 | 1. a time series X, with lag tau and embedding dimension dE (default) 8 | 2. a list, W, of normalized singular values of a matrix (if W is provided, 9 | recommend to speed up.) 10 | 11 | If W is None, the function will do as follows to prepare singular spectrum: 12 | 13 | First, computer an embedding matrix from X, Tau and DE using pyeeg 14 | function embed_seq(): 15 | M = embed_seq(X, Tau, DE) 16 | 17 | Second, use scipy.linalg function svd to decompose the embedding matrix 18 | M and obtain a list of singular values: 19 | W = svd(M, compute_uv=0) 20 | 21 | At last, normalize W: 22 | W /= sum(W) 23 | 24 | Notes 25 | ------------- 26 | 27 | To speed up, it is recommended to compute W before calling this function 28 | because W may also be used by other functions whereas computing it here 29 | again will slow down. 30 | """ 31 | 32 | if W is None: 33 | Y = embed_seq(X, Tau, DE) 34 | W = numpy.linalg.svd(Y, compute_uv=0) 35 | W /= sum(W) # normalize singular values 36 | 37 | return -1 * sum(W * numpy.log(W)) 38 | -------------------------------------------------------------------------------- /pyeeg/fractal_dimension.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | 3 | 4 | def hfd(X, Kmax): 5 | """ Compute Higuchi Fractal Dimension of a time series X. kmax 6 | is an HFD parameter 7 | """ 8 | L = [] 9 | x = [] 10 | N = len(X) 11 | for k in range(1, Kmax): 12 | Lk = [] 13 | for m in range(0, k): 14 | Lmk = 0 15 | for i in range(1, int(numpy.floor((N - m) / k))): 16 | Lmk += abs(X[m + i * k] - X[m + i * k - k]) 17 | Lmk = Lmk * (N - 1) / numpy.floor((N - m) / float(k)) / k 18 | Lk.append(Lmk) 19 | L.append(numpy.log(numpy.mean(Lk))) 20 | x.append([numpy.log(float(1) / k), 1]) 21 | 22 | (p, _, _, _) = numpy.linalg.lstsq(x, L) 23 | return p[0] 24 | 25 | 26 | def pfd(X, D=None): 27 | """Compute Petrosian Fractal Dimension of a time series from either two 28 | cases below: 29 | 1. X, the time series of type list (default) 30 | 2. D, the first order differential sequence of X (if D is provided, 31 | recommended to speed up) 32 | 33 | In case 1, D is computed using Numpy's difference function. 34 | 35 | To speed up, it is recommended to compute D before calling this function 36 | because D may also be used by other functions whereas computing it here 37 | again will slow down. 38 | """ 39 | if D is None: 40 | D = numpy.diff(X) 41 | D = D.tolist() 42 | N_delta = 0 # number of sign changes in derivative of the signal 43 | for i in range(1, len(D)): 44 | if D[i] * D[i - 1] < 0: 45 | N_delta += 1 46 | n = len(X) 47 | return numpy.log10(n) / ( 48 | numpy.log10(n) + numpy.log10(n / n + 0.4 * N_delta) 49 | ) 50 | -------------------------------------------------------------------------------- /pyeeg/hjorth_mobility_complexity.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | 3 | 4 | def hjorth(X, D=None): 5 | """ Compute Hjorth mobility and complexity of a time series from either two 6 | cases below: 7 | 1. X, the time series of type list (default) 8 | 2. D, a first order differential sequence of X (if D is provided, 9 | recommended to speed up) 10 | 11 | In case 1, D is computed using Numpy's Difference function. 12 | 13 | Notes 14 | ----- 15 | To speed up, it is recommended to compute D before calling this function 16 | because D may also be used by other functions whereas computing it here 17 | again will slow down. 18 | 19 | Parameters 20 | ---------- 21 | 22 | X 23 | list 24 | 25 | a time series 26 | 27 | D 28 | list 29 | 30 | first order differential sequence of a time series 31 | 32 | Returns 33 | ------- 34 | 35 | As indicated in return line 36 | 37 | Hjorth mobility and complexity 38 | 39 | """ 40 | 41 | if D is None: 42 | D = numpy.diff(X) 43 | D = D.tolist() 44 | 45 | D.insert(0, X[0]) # pad the first difference 46 | D = numpy.array(D) 47 | 48 | n = len(X) 49 | 50 | M2 = float(sum(D ** 2)) / n 51 | TP = sum(numpy.array(X) ** 2) 52 | M4 = 0 53 | for i in range(1, len(D)): 54 | M4 += (D[i] - D[i - 1]) ** 2 55 | M4 = M4 / n 56 | 57 | return numpy.sqrt(M2 / TP), numpy.sqrt( 58 | float(M4) * TP / M2 / M2 59 | ) # Hjorth Mobility and Complexity 60 | -------------------------------------------------------------------------------- /pyeeg/hurst.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | 3 | 4 | def hurst(X): 5 | """ Compute the Hurst exponent of X. If the output H=0.5,the behavior 6 | of the time-series is similar to random walk. If H<0.5, the time-series 7 | cover less "distance" than a random walk, vice verse. 8 | 9 | Parameters 10 | ---------- 11 | 12 | X 13 | 14 | list 15 | 16 | a time series 17 | 18 | Returns 19 | ------- 20 | H 21 | 22 | float 23 | 24 | Hurst exponent 25 | 26 | Notes 27 | -------- 28 | Author of this function is Xin Liu 29 | 30 | Examples 31 | -------- 32 | 33 | >>> import pyeeg 34 | >>> from numpy.random import randn 35 | >>> a = randn(4096) 36 | >>> pyeeg.hurst(a) 37 | 0.5057444 38 | 39 | """ 40 | X = numpy.array(X) 41 | N = X.size 42 | T = numpy.arange(1, N + 1) 43 | Y = numpy.cumsum(X) 44 | Ave_T = Y / T 45 | 46 | S_T = numpy.zeros(N) 47 | R_T = numpy.zeros(N) 48 | 49 | for i in range(N): 50 | S_T[i] = numpy.std(X[:i + 1]) 51 | X_T = Y - T * Ave_T[i] 52 | R_T[i] = numpy.ptp(X_T[:i + 1]) 53 | 54 | R_S = R_T / S_T 55 | R_S = numpy.log(R_S)[1:] 56 | n = numpy.log(T)[1:] 57 | A = numpy.column_stack((n, numpy.ones(n.size))) 58 | [m, c] = numpy.linalg.lstsq(A, R_S)[0] 59 | H = m 60 | return H 61 | -------------------------------------------------------------------------------- /pyeeg/information_based_similarity.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | from .embedded_sequence import embed_seq 3 | 4 | 5 | def information_based_similarity(x, y, n): 6 | """Calculates the information based similarity of two time series x 7 | and y. 8 | 9 | Parameters 10 | ---------- 11 | 12 | x 13 | 14 | list 15 | 16 | a time series 17 | 18 | y 19 | 20 | list 21 | 22 | a time series 23 | 24 | n 25 | 26 | integer 27 | 28 | word order 29 | 30 | 31 | Returns 32 | ---------- 33 | IBS 34 | 35 | float 36 | 37 | Information based similarity 38 | 39 | 40 | Notes 41 | ---------- 42 | Information based similarity is a measure of dissimilarity between 43 | two time series. Let the sequences be x and y. Each sequence is first 44 | replaced by its first ordered difference(Encoder). Calculating the 45 | Heaviside of the resulting sequences, we get two binary sequences, 46 | SymbolicSeq. Using PyEEG function, embed_seq, with lag of 1 and dimension 47 | of n, we build an embedding matrix from the latter sequence. 48 | 49 | Each row of this embedding matrix is called a word. Information based 50 | similarity measures the distance between two sequence by comparing the 51 | rank of words in the sequences; more explicitly, the distance, D, is 52 | calculated using the formula: 53 | 54 | "1/2^(n-1) * sum( abs(Rank(0)(k)-R(1)(k)) * F(k) )" where Rank(0)(k) 55 | and Rank(1)(k) are the rank of the k-th word in each of the input 56 | sequences. F(k) is a modified "shannon" weighing function that increases 57 | the weight of each word in the calculations when they are more frequent in 58 | the sequences. 59 | 60 | It is advisable to calculate IBS for numerical sequences using 8-tupple 61 | words. 62 | 63 | References 64 | ---------- 65 | Yang AC, Hseu SS, Yien HW, Goldberger AL, Peng CK: Linguistic analysis of 66 | the human heartbeat using frequency and rank order statistics. Phys Rev 67 | Lett 2003, 90: 108103 68 | 69 | 70 | Examples 71 | ---------- 72 | >>> import pyeeg 73 | >>> from numpy.random import randn 74 | >>> x = randn(100) 75 | >>> y = randn(100) 76 | >>> pyeeg.information_based_similarity(x,y,8) 77 | 0.64512947848249214 78 | 79 | """ 80 | 81 | Wordlist = [] 82 | Space = [[0, 0], [0, 1], [1, 0], [1, 1]] 83 | Sample = [0, 1] 84 | 85 | if (n == 1): 86 | Wordlist = Sample 87 | 88 | if (n == 2): 89 | Wordlist = Space 90 | 91 | elif (n > 1): 92 | Wordlist = Space 93 | Buff = [] 94 | for k in range(0, n - 2): 95 | Buff = [] 96 | 97 | for i in range(0, len(Wordlist)): 98 | Buff.append(tuple(Wordlist[i])) 99 | Buff = tuple(Buff) 100 | 101 | Wordlist = [] 102 | for i in range(0, len(Buff)): 103 | for j in range(0, len(Sample)): 104 | Wordlist.append(list(Buff[i])) 105 | Wordlist[len(Wordlist) - 1].append(Sample[j]) 106 | 107 | Wordlist.sort() 108 | 109 | Input = [[], []] 110 | Input[0] = x 111 | Input[1] = y 112 | 113 | SymbolicSeq = [[], []] 114 | for i in range(0, 2): 115 | Encoder = numpy.diff(Input[i]) 116 | for j in range(0, len(Input[i]) - 1): 117 | if(Encoder[j] > 0): 118 | SymbolicSeq[i].append(1) 119 | else: 120 | SymbolicSeq[i].append(0) 121 | 122 | Wm = [] 123 | Wm.append(embed_seq(SymbolicSeq[0], 1, n).tolist()) 124 | Wm.append(embed_seq(SymbolicSeq[1], 1, n).tolist()) 125 | 126 | Count = [[], []] 127 | for i in range(0, 2): 128 | for k in range(0, len(Wordlist)): 129 | Count[i].append(Wm[i].count(Wordlist[k])) 130 | 131 | Prob = [[], []] 132 | for i in range(0, 2): 133 | Sigma = 0 134 | for j in range(0, len(Wordlist)): 135 | Sigma += Count[i][j] 136 | for k in range(0, len(Wordlist)): 137 | Prob[i].append(numpy.true_divide(Count[i][k], Sigma)) 138 | 139 | Entropy = [[], []] 140 | for i in range(0, 2): 141 | for k in range(0, len(Wordlist)): 142 | if (Prob[i][k] == 0): 143 | Entropy[i].append(0) 144 | else: 145 | Entropy[i].append(Prob[i][k] * (numpy.log2(Prob[i][k]))) 146 | 147 | Rank = [[], []] 148 | Buff = [[], []] 149 | Buff[0] = tuple(Count[0]) 150 | Buff[1] = tuple(Count[1]) 151 | for i in range(0, 2): 152 | Count[i].sort() 153 | Count[i].reverse() 154 | for k in range(0, len(Wordlist)): 155 | Rank[i].append(Count[i].index(Buff[i][k])) 156 | Count[i][Count[i].index(Buff[i][k])] = -1 157 | 158 | IBS = 0 159 | Z = 0 160 | n = 0 161 | for k in range(0, len(Wordlist)): 162 | if ((Buff[0][k] != 0) & (Buff[1][k] != 0)): 163 | F = -Entropy[0][k] - Entropy[1][k] 164 | IBS += numpy.multiply(numpy.absolute(Rank[0][k] - Rank[1][k]), F) 165 | Z += F 166 | else: 167 | n += 1 168 | 169 | IBS = numpy.true_divide(IBS, Z) 170 | IBS = numpy.true_divide(IBS, len(Wordlist) - n) 171 | 172 | return IBS 173 | -------------------------------------------------------------------------------- /pyeeg/largest_lyauponov_exponent.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | 3 | 4 | def LLE(x, tau, n, T, fs): 5 | """Calculate largest Lyauponov exponent of a given time series x using 6 | Rosenstein algorithm. 7 | 8 | Parameters 9 | ---------- 10 | 11 | x 12 | list 13 | 14 | a time series 15 | 16 | n 17 | integer 18 | 19 | embedding dimension 20 | 21 | tau 22 | integer 23 | 24 | Embedding lag 25 | 26 | fs 27 | integer 28 | 29 | Sampling frequency 30 | 31 | T 32 | integer 33 | 34 | Mean period 35 | 36 | Returns 37 | ---------- 38 | 39 | Lexp 40 | float 41 | 42 | Largest Lyapunov Exponent 43 | 44 | Notes 45 | ---------- 46 | A n-dimensional trajectory is first reconstructed from the observed data by 47 | use of embedding delay of tau, using pyeeg function, embed_seq(x, tau, n). 48 | Algorithm then searches for nearest neighbour of each point on the 49 | reconstructed trajectory; temporal separation of nearest neighbours must be 50 | greater than mean period of the time series: the mean period can be 51 | estimated as the reciprocal of the mean frequency in power spectrum 52 | 53 | Each pair of nearest neighbours is assumed to diverge exponentially at a 54 | rate given by largest Lyapunov exponent. Now having a collection of 55 | neighbours, a least square fit to the average exponential divergence is 56 | calculated. The slope of this line gives an accurate estimate of the 57 | largest Lyapunov exponent. 58 | 59 | References 60 | ---------- 61 | Rosenstein, Michael T., James J. Collins, and Carlo J. De Luca. "A 62 | practical method for calculating largest Lyapunov exponents from small data 63 | sets." Physica D: Nonlinear Phenomena 65.1 (1993): 117-134. 64 | 65 | 66 | Examples 67 | ---------- 68 | >>> import pyeeg 69 | >>> X = numpy.array([3,4,1,2,4,51,4,32,24,12,3,45]) 70 | >>> pyeeg.LLE(X,2,4,1,1) 71 | 0.18771136179353307 72 | 73 | """ 74 | 75 | from embedded_sequence import embed_seq 76 | 77 | Em = embed_seq(x, tau, n) 78 | M = len(Em) 79 | A = numpy.tile(Em, (len(Em), 1, 1)) 80 | B = numpy.transpose(A, [1, 0, 2]) 81 | 82 | # square_dists[i,j,k] = (Em[i][k]-Em[j][k])^2 83 | square_dists = (A - B) ** 2 84 | 85 | # D[i,j] = ||Em[i]-Em[j]||_2 86 | D = numpy.sqrt(square_dists[:, :, :].sum(axis=2)) 87 | 88 | # Exclude elements within T of the diagonal 89 | band = numpy.tri(D.shape[0], k=T) - numpy.tri(D.shape[0], k=-T - 1) 90 | band[band == 1] = numpy.inf 91 | 92 | # nearest neighbors more than T steps away 93 | neighbors = (D + band).argmin(axis=0) 94 | 95 | # in_bounds[i,j] = (i+j <= M-1 and i+neighbors[j] <= M-1) 96 | inc = numpy.tile(numpy.arange(M), (M, 1)) 97 | row_inds = (numpy.tile(numpy.arange(M), (M, 1)).T + inc) 98 | col_inds = (numpy.tile(neighbors, (M, 1)) + inc.T) 99 | in_bounds = numpy.logical_and(row_inds <= M - 1, col_inds <= M - 1) 100 | 101 | # Uncomment for old (miscounted) version 102 | # in_bounds = numpy.logical_and(row_inds < M - 1, col_inds < M - 1) 103 | row_inds[~in_bounds] = 0 104 | col_inds[~in_bounds] = 0 105 | 106 | # neighbor_dists[i,j] = ||Em[i+j]-Em[i+neighbors[j]]||_2 107 | neighbor_dists = numpy.ma.MaskedArray(D[row_inds, col_inds], ~in_bounds) 108 | 109 | # number of in-bounds indices by row 110 | J = (~neighbor_dists.mask).sum(axis=1) 111 | 112 | # Set invalid (zero) values to 1; log(1) = 0 so sum is unchanged 113 | neighbor_dists[neighbor_dists == 0] = 1 114 | d_ij = numpy.sum(numpy.log(neighbor_dists.data), axis=1) 115 | mean_d = d_ij[J > 0] / J[J > 0] 116 | 117 | x = numpy.arange(len(mean_d)) 118 | X = numpy.vstack((x, numpy.ones(len(mean_d)))).T 119 | [m, c] = numpy.linalg.lstsq(X, mean_d)[0] 120 | Lexp = fs * m 121 | return Lexp 122 | 123 | 124 | if __name__ == "__main__": 125 | import doctest 126 | doctest.testmod() 127 | -------------------------------------------------------------------------------- /pyeeg/spectrum.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | 3 | 4 | def bin_power(X, Band, Fs): 5 | """Compute power in each frequency bin specified by Band from FFT result of 6 | X. By default, X is a real signal. 7 | 8 | Note 9 | ----- 10 | A real signal can be synthesized, thus not real. 11 | 12 | Parameters 13 | ----------- 14 | 15 | Band 16 | list 17 | 18 | boundary frequencies (in Hz) of bins. They can be unequal bins, e.g. 19 | [0.5,4,7,12,30] which are delta, theta, alpha and beta respectively. 20 | You can also use range() function of Python to generate equal bins and 21 | pass the generated list to this function. 22 | 23 | Each element of Band is a physical frequency and shall not exceed the 24 | Nyquist frequency, i.e., half of sampling frequency. 25 | 26 | X 27 | list 28 | 29 | a 1-D real time series. 30 | 31 | Fs 32 | integer 33 | 34 | the sampling rate in physical frequency 35 | 36 | Returns 37 | ------- 38 | 39 | Power 40 | list 41 | 42 | spectral power in each frequency bin. 43 | 44 | Power_ratio 45 | list 46 | 47 | spectral power in each frequency bin normalized by total power in ALL 48 | frequency bins. 49 | 50 | """ 51 | 52 | C = numpy.fft.fft(X) 53 | C = abs(C) 54 | Power = numpy.zeros(len(Band) - 1) 55 | for Freq_Index in range(0, len(Band) - 1): 56 | Freq = float(Band[Freq_Index]) 57 | Next_Freq = float(Band[Freq_Index + 1]) 58 | Power[Freq_Index] = sum( 59 | C[int(numpy.floor(Freq / Fs * len(X))): 60 | int(numpy.floor(Next_Freq / Fs * len(X)))] 61 | ) 62 | Power_Ratio = Power / sum(Power) 63 | return Power, Power_Ratio 64 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | description-file = README.md 3 | [bdist_wheel] 4 | # This flag says that the code is written to work on both Python 2 and Python 5 | # 3. If at all possible, it is good practice to do this. If you cannot, you 6 | # will need to generate wheels for each Python version that you support. 7 | universal=1 8 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | 3 | 4 | setup( 5 | name='pyeeg', 6 | version='0.4.4', 7 | description='A Python module to extract EEG features', 8 | url='https://github.com/forrestbao/pyeeg', 9 | author='Forrest Bao and all contributors', 10 | license='GNU GPL v3', 11 | packages=['pyeeg'], 12 | install_requires=[ 13 | 'numpy>=1.9.2', 14 | ], 15 | test_suite='tests', 16 | classifiers=[ 17 | 'Development Status :: 4 - Beta', 18 | 'Environment :: Console', 19 | 'Intended Audience :: Science/Research', 20 | 'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)', 21 | 'Operating System :: OS Independent', 22 | 'Programming Language :: Python :: 2', 23 | 'Programming Language :: Python :: 2.7', 24 | 'Programming Language :: Python :: 3', 25 | 'Programming Language :: Python :: 3.3', 26 | 'Programming Language :: Python :: 3.4', 27 | 'Programming Language :: Python :: 3.5', 28 | 'Programming Language :: Python :: 3.6', 29 | 'Topic :: Scientific/Engineering :: Bio-Informatics', 30 | 'Topic :: Scientific/Engineering :: Information Analysis', 31 | 'Topic :: Scientific/Engineering :: Mathematics', 32 | ], 33 | ) 34 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/forrestbao/pyeeg/a6c18bb093e4748f9d9c208535a6ae024a0802b8/tests/__init__.py -------------------------------------------------------------------------------- /tests/demo_data/sampentest.txt: -------------------------------------------------------------------------------- 1 | -4.3256481152822068e-001 2 | -1.6655843782380970e+000 3 | 1.2533230647483068e-001 4 | 2.8767642035854885e-001 5 | -1.1464713506814637e+000 6 | 1.1909154656429988e+000 7 | 1.1891642016521031e+000 8 | -3.7633276593317645e-002 9 | 3.2729236140865414e-001 10 | 1.7463914282092452e-001 11 | -1.8670857768143936e-001 12 | 7.2579054829330270e-001 13 | -5.8831654301418868e-001 14 | 2.1831858181971011e+000 15 | -1.3639588308659570e-001 16 | 1.1393131352080962e-001 17 | 1.0667682113591888e+000 18 | 5.9281460523605348e-002 19 | -9.5648405483669041e-002 20 | -8.3234946365002249e-001 21 | 2.9441081639264038e-001 22 | -1.3361818579378040e+000 23 | 7.1432455181895216e-001 24 | 1.6235620644462707e+000 25 | -6.9177570170228675e-001 26 | 8.5799667282826264e-001 27 | 1.2540014216025324e+000 28 | -1.5937295764474768e+000 29 | -1.4409644319010200e+000 30 | 5.7114762365817795e-001 31 | -3.9988557771536315e-001 32 | 6.8999737546434514e-001 33 | 8.1562228887614330e-001 34 | 7.1190832350089328e-001 35 | 1.2902497549324770e+000 36 | 6.6860050568204032e-001 37 | 1.1908380742433691e+000 38 | -1.2024571147739440e+000 39 | -1.9789557768770449e-002 40 | -1.5671729883198068e-001 41 | -1.6040855620011585e+000 42 | 2.5730423467748986e-001 43 | -1.0564729280814824e+000 44 | 1.4151414858723386e+000 45 | -8.0509040419687983e-001 46 | 5.2874301096222487e-001 47 | 2.1932067266762237e-001 48 | -9.2190162435553913e-001 49 | -2.1706744943052625e+000 50 | -5.9187824521191180e-002 51 | -1.0106337064742474e+000 52 | 6.1446304889548098e-001 53 | 5.0774078534198552e-001 54 | 1.6924298701905214e+000 55 | 5.9128258692417590e-001 56 | -6.4359520268252612e-001 57 | 3.8033725171391014e-001 58 | -1.0091155243407850e+000 59 | -1.9510669530289293e-002 60 | -4.8220789145312269e-002 61 | 4.3191841625545013e-005 62 | -3.1785945124768789e-001 63 | 1.0950037387874925e+000 64 | -1.8739902576409608e+000 65 | 4.2818327304516285e-001 66 | 8.9563847121175177e-001 67 | 7.3095733842945332e-001 68 | 5.7785734633079844e-001 69 | 4.0314031618440292e-002 70 | 6.7708918759730474e-001 71 | 5.6890020520072304e-001 72 | -2.5564541563196480e-001 73 | -3.7746895552236126e-001 74 | -2.9588711000355705e-001 75 | -1.4751345058552594e+000 76 | -2.3400404765603303e-001 77 | 1.1844483705412130e-001 78 | 3.1480904339505583e-001 79 | 1.4435082443498206e+000 80 | -3.5097473832774179e-001 81 | 6.2323385113849417e-001 82 | 7.9904861814777828e-001 83 | 9.4088994072778043e-001 84 | -9.9209173554379526e-001 85 | 2.1203515216505542e-001 86 | 2.3788207287557869e-001 87 | -1.0077633916782680e+000 88 | -7.4204475213360388e-001 89 | 1.0822949531553336e+000 90 | -1.3149970294527352e-001 91 | 3.8988048968703898e-001 92 | 8.7987106579793015e-002 93 | -6.3546522547931616e-001 94 | -5.5957330219624102e-001 95 | 4.4365348950366740e-001 96 | -9.4990379854764539e-001 97 | 7.8118161787839147e-001 98 | 5.6896064572327387e-001 99 | -8.2171429169625565e-001 100 | -2.6560685133254908e-001 101 | -1.1877770164698040e+000 102 | -2.2023207173234383e+000 103 | 9.8633739100202267e-001 104 | -5.1863506634474621e-001 105 | 3.2736756408083439e-001 106 | 2.3405701284718494e-001 107 | 2.1466138879094456e-002 108 | -1.0039444667477249e+000 109 | -9.4714606473854135e-001 110 | -3.7442919502916561e-001 111 | -1.1858862138085282e+000 112 | -1.0559029235236910e+000 113 | 1.4724799344199151e+000 114 | 5.5743831837843170e-002 115 | -1.2173174537045510e+000 116 | -4.1227133686432105e-002 117 | -1.1283438643202286e+000 118 | -1.3492775431024946e+000 119 | -2.6110162306162105e-001 120 | 9.5346544550481849e-001 121 | 1.2864443004664500e-001 122 | 6.5646751388539604e-001 123 | -1.1678193647266388e+000 124 | -4.6060517950615043e-001 125 | -2.6243995283833266e-001 126 | -1.2131520684939066e+000 127 | -1.3194369981095369e+000 128 | 9.3121751499543615e-001 129 | 1.1244896384133726e-002 130 | -6.4514581569117024e-001 131 | 8.0572879311237566e-001 132 | 2.3162601078043654e-001 133 | -9.8975967168200418e-001 134 | 1.3395857006103875e+000 135 | 2.8950203453841322e-001 136 | 1.4789170576812780e+000 137 | 1.1380280128583706e+000 138 | -6.8413858513633963e-001 139 | -1.2919360449659378e+000 140 | -7.2926276263646728e-002 141 | -3.3059887989276432e-001 142 | -8.4362763915479966e-001 143 | 4.9776966418278246e-001 144 | 1.4884904709034834e+000 145 | -5.4647589476762259e-001 146 | -8.4675816388305947e-001 147 | -2.4633652808489975e-001 148 | 6.6302414585590774e-001 149 | -8.5419737446897992e-001 150 | -1.2013148153390409e+000 151 | -1.1986942805738719e-001 152 | -6.5294014841586534e-002 153 | 4.8529555591654394e-001 154 | -5.9549090261947590e-001 155 | -1.4966774382447526e-001 156 | -4.3475193115253336e-001 157 | -7.9330223023420576e-002 158 | 1.5351522661221475e+000 159 | -6.0648285927726564e-001 160 | -1.3473626738502404e+000 161 | 4.6938311986633002e-001 162 | -9.0356694261777637e-001 163 | 3.5879638729476929e-002 164 | -6.2753121996683148e-001 165 | 5.3539795424910597e-001 166 | 5.5288351742382202e-001 167 | -2.0369047956735789e-001 168 | -2.0543246805566060e+000 169 | 1.3256073141727984e-001 170 | 1.5929407037660153e+000 171 | 1.0184117886247104e+000 172 | -1.5804024993031622e+000 173 | -7.8661919359452090e-002 174 | -6.8165686000236303e-001 175 | -1.0245530574290316e+000 176 | -1.2343534779842618e+000 177 | 2.8880701873033965e-001 178 | -4.2930300455191500e-001 179 | 5.5801190176472580e-002 180 | -3.6787356674063804e-001 181 | -4.6497336717111842e-001 182 | 3.7096058384895175e-001 183 | 7.2828293155149471e-001 184 | 2.1121601697715047e+000 185 | -1.3572977430967532e+000 186 | -1.0226101443342059e+000 187 | 1.0378341987187603e+000 188 | -3.8979954847683068e-001 189 | -1.3812656240198373e+000 190 | 3.1554263277236466e-001 191 | 1.5532425685153481e+000 192 | 7.0789388463247582e-001 193 | 1.9573847551475061e+000 194 | 5.0454235359216570e-001 195 | 1.8645290204853029e+000 196 | -3.3981177741496377e-001 197 | -1.1397794023132348e+000 198 | -2.1112348338025799e-001 199 | 1.1902449362512015e+000 200 | -1.1162087577856099e+000 201 | 6.3527413474712147e-001 202 | -6.0141212626972518e-001 203 | 5.5118471182490203e-001 204 | -1.0998404547108134e+000 205 | 8.5990593293718429e-002 206 | -2.0045633215907919e+000 207 | -4.9308791765969695e-001 208 | 4.6204801179919308e-001 209 | -3.2100469218129207e-001 210 | 1.2365556516019161e+000 211 | -6.3127965672514641e-001 212 | -2.3252111288837711e+000 213 | -1.2316365333250152e+000 214 | 1.0556483879024596e+000 215 | -1.1322398936902489e-001 216 | 3.7922362268503290e-001 217 | 9.4419972674730834e-001 218 | -2.1204266882242115e+000 219 | -6.4467891554193690e-001 220 | -7.0430172843360894e-001 221 | -1.0181372163990707e+000 222 | -1.8208186841138524e-001 223 | 1.5210132390055870e+000 224 | -3.8438763886711559e-002 225 | 1.2274479890097165e+000 226 | -6.9620480003288876e-001 227 | 7.5244865230144464e-003 228 | -7.8289304437828722e-001 229 | 5.8693855921443094e-001 230 | -2.5120737456888181e-001 231 | 4.8013582284260076e-001 232 | 6.6815503443364055e-001 233 | -7.8321196273411942e-002 234 | 8.8917261841259909e-001 235 | 2.3092874859523866e+000 236 | 5.2463867977109835e-001 237 | -1.1787323951306753e-002 238 | 9.1314081776137068e-001 239 | 5.5940678888401998e-002 240 | -1.1070698948260072e+000 241 | 4.8549770731281022e-001 242 | -5.0050737555313854e-003 243 | -2.7621785935475895e-001 244 | 1.2764524736743927e+000 245 | 1.8634006131845375e+000 246 | -5.2255930163639908e-001 247 | 1.0342444693731498e-001 248 | -8.0764913089718049e-001 249 | 6.8043858374894572e-001 250 | -2.3645898479415810e+000 251 | 9.9011487204949045e-001 252 | 2.1889912088117661e-001 253 | 2.6166246016140166e-001 254 | 1.2134444949753469e+000 255 | -2.7466698645678145e-001 256 | -1.3313445081352937e-001 257 | -1.2705002037083766e+000 258 | -1.6636064528297720e+000 259 | -7.0355426153675493e-001 260 | 2.8088048852330211e-001 261 | -5.4120932991619408e-001 262 | -1.3335307297363925e+000 263 | 1.0726862678901432e+000 264 | -7.1208545249435584e-001 265 | -1.1285561230685560e-002 266 | -8.1702919569583610e-004 267 | -2.4943628469543444e-001 268 | 3.9657531871165158e-001 269 | -2.6401335492224315e-001 270 | -1.6640108769305890e+000 271 | -1.0289750995438010e+000 272 | 2.4309470022456500e-001 273 | -1.2565901078338166e+000 274 | -3.4718318973352613e-001 275 | -9.4137219342832856e-001 276 | -1.1745602813024438e+000 277 | -1.0211416869357750e+000 278 | -4.0166673459678831e-001 279 | 1.7366566856230725e-001 280 | -1.1611849335051072e-001 281 | 1.0641191489863535e+000 282 | -2.4538629675166962e-001 283 | -1.5175391310895556e+000 284 | 9.7341591259511185e-003 285 | 7.1372864855954732e-002 286 | 3.1653581376850820e-001 287 | 4.9982566779647836e-001 288 | 1.2780841467141097e+000 289 | -5.4781614692115776e-001 290 | 2.6080839887907459e-001 291 | -1.3176671873511559e-002 292 | -5.8026400214195251e-001 293 | 2.1363084228053086e+000 294 | -2.5761711565348083e-001 295 | -1.4095284893691984e+000 296 | 1.7701008928516144e+000 297 | 3.2554598476071001e-001 298 | -1.1190395753813116e+000 299 | 6.2035013944552475e-001 300 | 1.2697818471897746e+000 301 | -8.9604250642191452e-001 302 | 1.3517544475843685e-001 303 | -1.3904001004044259e-001 304 | -1.1633952938372654e+000 305 | 1.1837195399368565e+000 306 | -1.5429661783325022e-002 307 | 5.3621869471861705e-001 308 | -7.1642862372585547e-001 309 | -6.5555938950390591e-001 310 | 3.1436276331074814e-001 311 | 1.0681407593458775e-001 312 | 1.8482162180189687e+000 313 | -2.7510567543881131e-001 314 | 2.2125540789896809e+000 315 | 1.5085257560961467e+000 316 | -1.9450785999193310e+000 317 | -1.6805427775226454e+000 318 | -5.7353413410587606e-001 319 | -1.8581652736765947e-001 320 | 8.9341156765677023e-003 321 | 8.3694989083729465e-001 322 | -7.2227067243329512e-001 323 | -7.2149047716441006e-001 324 | -2.0118099951714263e-001 325 | -2.0464161095144321e-002 326 | 2.7888999991245078e-001 327 | 1.0582948144500000e+000 328 | 6.2167328240240960e-001 329 | -1.7506152884853836e+000 330 | 6.9734755148343741e-001 331 | 8.1148586331699257e-001 332 | 6.3634494760413318e-001 333 | 1.3100803414102620e+000 334 | 3.2709751591819802e-001 335 | -6.7299316385471109e-001 336 | -1.4932749947673082e-001 337 | -2.4490177537568125e+000 338 | 4.7328561224355359e-001 339 | 1.1694565679328851e-001 340 | -5.9110383863220495e-001 341 | -6.5470767508278371e-001 342 | -1.0806618512116946e+000 343 | -4.7730865297905170e-002 344 | 3.7934453728879497e-001 345 | -3.3036104579865933e-001 346 | -4.9989825118472925e-001 347 | -3.5978607953005746e-002 348 | -1.7476033119671699e-001 349 | -9.5726507882166145e-001 350 | 1.2925479001322682e+000 351 | 4.4090964284702200e-001 352 | 1.2809409427445406e+000 353 | -4.9772980521188004e-001 354 | -1.1187166376043225e+000 355 | 8.0764961943935132e-001 356 | 4.1199578638244888e-002 357 | -7.5620860554670111e-001 358 | -8.9129147806430040e-002 359 | -2.0088503217891547e+000 360 | 1.0839180379588267e+000 361 | -9.8119056314417352e-001 362 | -6.8848863746469791e-001 363 | 1.3394794818077986e+000 364 | -9.0924316031600994e-001 365 | -4.1285772861879833e-001 366 | -5.0616318564854024e-001 367 | 1.6197477991253717e+000 368 | 8.0900711206500039e-002 369 | -1.0810564901769375e+000 370 | -1.1245178115942032e+000 371 | 1.7356763426062964e+000 372 | 1.9374585965267537e+000 373 | 1.6350682185206411e+000 374 | -1.2559401667743206e+000 375 | -2.1353750620870260e-001 376 | -1.9893204828268177e-001 377 | 3.0749917747984890e-001 378 | -5.7232545648506006e-001 379 | -9.7764836704205615e-001 380 | -4.4680940665694829e-001 381 | 1.0820919008951635e+000 382 | 2.3726479493899850e+000 383 | 2.2928833610443120e-001 384 | -2.6662313612389132e-001 385 | 7.0167217691939954e-001 386 | -4.8759049128980936e-001 387 | 1.8624797253190992e+000 388 | 1.1068511103913441e+000 389 | -1.2275657222158463e+000 390 | -6.6988511005648677e-001 391 | 1.3409294523313127e+000 392 | 3.8808331624114234e-001 393 | 3.9305892877699972e-001 394 | -1.7073335778377412e+000 395 | 2.2785864470433817e-001 396 | 6.8563285776295124e-001 397 | -6.3679011291329279e-001 398 | -1.0026055542338093e+000 399 | -1.8562067291101580e-001 400 | -1.0540327142000288e+000 401 | -7.1539488916578894e-002 402 | 2.7919841968634951e-001 403 | 1.3732753424840702e+000 404 | 1.7984103218475750e-001 405 | -5.4201655650396363e-001 406 | 1.6341905807507420e+000 407 | 8.2521515151758584e-001 408 | 2.3076114227231159e-001 409 | 6.7163394593208492e-001 410 | -5.0807788041779367e-001 411 | 8.5635159733999011e-001 412 | 2.6850345353239546e-001 413 | 6.2497517619067067e-001 414 | -1.0473379377146483e+000 415 | 1.5356703814685793e+000 416 | 4.3442573789581168e-001 417 | -1.9171358529717730e+000 418 | 4.6993952444861936e-001 419 | 1.2743511328250361e+000 420 | 6.3854245107310015e-001 421 | 1.3807824763675156e+000 422 | 1.3198428558313753e+000 423 | -9.0942923645811313e-001 424 | -2.3056050522651850e+000 425 | 1.7887302446237088e+000 426 | 3.9079780825821459e-001 427 | 2.0323676372437226e-002 428 | -4.0597700332319314e-001 429 | -1.5348945487974155e+000 430 | 2.2137310235762894e-001 431 | -1.3744786542148590e+000 432 | -8.3928553082155788e-001 433 | -2.0864255966197187e-001 434 | 7.5591299878680163e-001 435 | 3.7573445258628185e-001 436 | -1.3454129656607750e+000 437 | 1.4818762459970862e+000 438 | 3.2736137578809076e-002 439 | 1.8704528253922521e+000 440 | -1.2089905241048509e+000 441 | -7.8263186783422245e-001 442 | -7.6729852412104849e-001 443 | -1.0720010478431583e-001 444 | -9.7705667196127377e-001 445 | -9.6398811657877514e-001 446 | -2.3791723526715298e+000 447 | -8.3818791465633546e-001 448 | 2.5734563499436619e-001 449 | -1.8383400014095083e-001 450 | -1.6761529619977827e-001 451 | -1.1698890871467590e-001 452 | 1.6848817375370478e-001 453 | -5.0120629632352731e-001 454 | -7.0507642354191702e-001 455 | 5.0816468399248071e-001 456 | -4.2092153577171987e-001 457 | 2.2913337207241180e-001 458 | -9.5949702639188150e-001 459 | -1.4604258822177071e-001 460 | 7.4453802715371831e-001 461 | -8.9049603327509885e-001 462 | 1.3906185865601664e-001 463 | -2.3614429715804758e-001 464 | -7.5459129032857661e-002 465 | -3.5857191276611505e-001 466 | -2.0776348552980579e+000 467 | -1.4354571023698079e-001 468 | 1.3933414749210382e+000 469 | 6.5180409165740849e-001 470 | -3.7713355773963853e-001 471 | -6.6144305947104565e-001 472 | 2.4895797618975368e-001 473 | -3.8351615721667676e-001 474 | -5.2847980388937532e-001 475 | 5.5388364270311734e-002 476 | 1.2537685710666626e+000 477 | -2.5200036394399365e+000 478 | 5.8485612035418399e-001 479 | -1.0080644173089854e+000 480 | 9.4428482457310081e-001 481 | -2.4239571338450290e+000 482 | -2.2383142849881707e-001 483 | 5.8069882735471236e-002 484 | -4.2461401505649093e-001 485 | -2.0291794534072446e-001 486 | -1.5130769789982312e+000 487 | -1.1263518610131702e+000 488 | -8.1500215772839479e-001 489 | 3.6661426970152483e-001 490 | -5.8610675846085603e-001 491 | 1.5374090260425568e+000 492 | 1.4007152852574289e-001 493 | -1.8627666658773090e+000 494 | -4.5419309698324789e-001 495 | -6.5207410523621245e-001 496 | 1.0331787692255201e-001 497 | -2.2063162198258865e-001 498 | -2.7904336657061335e-001 499 | -7.3366201304505074e-001 500 | -6.4533580168853980e-002 501 | -1.4440040658779980e+000 502 | 6.1234029223737352e-001 503 | -1.3235029618032093e+000 504 | -6.6157667657724395e-001 505 | -1.4611450503437784e-001 506 | 2.4808495822675208e-001 507 | -7.6632557379239005e-002 508 | 1.7381699701538176e+000 509 | 1.6219718997877377e+000 510 | 6.2643589682312906e-001 511 | 9.1813590225913552e-002 512 | -8.0760704650874726e-001 513 | -4.6133709421872093e-001 514 | -1.4059691942684509e+000 515 | -3.7452963273531803e-001 516 | -4.7091123634376558e-001 517 | 1.7512956264276767e+000 518 | 7.5322461750340575e-001 519 | 6.4989341476980364e-002 520 | -2.9276425865359323e-001 521 | 8.2822847199424537e-002 522 | 7.6619148033876217e-001 523 | 2.2368498781009816e+000 524 | 3.2688672516205608e-001 525 | 8.6330394268156485e-001 526 | 6.7938660174195831e-001 527 | 5.5475762588310240e-001 528 | 1.0016304273089194e+000 529 | 1.2593651481189680e+000 530 | 4.4151065192012819e-002 531 | -3.1413767474565191e-001 532 | 2.2670764087427511e-001 533 | 9.9669193290845393e-001 534 | 1.2159117190131969e+000 535 | -5.4270241586089962e-001 536 | 9.1222834229924443e-001 537 | -1.7214113232944259e-001 538 | -3.3595463728095515e-001 539 | 5.4148677646411847e-001 540 | 9.3211121349110748e-001 541 | -5.7025264752726357e-001 542 | -1.4986053783994235e+000 543 | -5.0345644019042325e-002 544 | 5.5302477378873527e-001 545 | 8.3497886682452727e-002 546 | 1.5775235124089682e+000 547 | -3.3077420319113976e-001 548 | 7.9515483199829706e-001 549 | -7.8480015048190344e-001 550 | -1.2631214870993845e+000 551 | 6.6665498604277351e-001 552 | -1.3926322050346449e+000 553 | -1.3005624647030269e+000 554 | -6.0502215908433565e-001 555 | -1.4885645044331768e+000 556 | 5.5854295799593912e-001 557 | -2.7735429146565144e-001 558 | -1.2936847598522185e+000 559 | -8.8843518137936861e-001 560 | -9.8652007625449556e-001 561 | -7.1617644436624828e-002 562 | -2.4145909345801972e+000 563 | -6.9434901111914316e-001 564 | -1.3913890115665006e+000 565 | 3.2964779928237514e-001 566 | 5.9854447999166360e-001 567 | 1.4717539803566831e-001 568 | -1.0143899070373294e-001 569 | -2.6349808422200045e+000 570 | 2.8053414090014619e-002 571 | -8.7631012622268989e-001 572 | -2.6547744791284611e-001 573 | -3.2757791031003242e-001 574 | -1.1582474864169829e+000 575 | 5.8005321065211068e-001 576 | 2.3975572722305211e-001 577 | -3.5088491838191171e-001 578 | 8.9209848362342525e-001 579 | 1.5782988358205232e+000 580 | -1.1081739325708244e+000 581 | -2.5931046975712430e-002 582 | -1.1106277156089546e+000 583 | 7.5083417769790350e-001 584 | 5.0016703215394931e-001 585 | -5.1726088476530196e-001 586 | -5.5920948981830709e-001 587 | -7.5337062086567663e-001 588 | 9.2581269305880642e-001 589 | -2.4852031900480015e-001 590 | -1.4983451724662422e-001 591 | -1.2584153777730664e+000 592 | 3.1261987583866419e-001 593 | 2.6902769360063012e+000 594 | 2.8969629211422804e-001 595 | -1.4228030065990676e+000 596 | 2.4678571548398118e-001 597 | -1.4357728810904431e+000 598 | 1.4857312713838181e-001 599 | -1.6930725688350658e+000 600 | 7.1918848102658095e-001 601 | 1.1417728306073511e+000 602 | 1.5519362755905890e+000 603 | 1.3836301143044067e+000 604 | -7.5809225438954519e-001 605 | 4.4266274156259322e-001 606 | 9.1109790133759794e-001 607 | -1.0740856172401285e+000 608 | 2.0176190936920457e-001 609 | 7.6286322314263832e-001 610 | -1.2881871974223793e+000 611 | -9.5296182463183576e-001 612 | 7.7817450051825032e-001 613 | -6.3310695599488910e-003 614 | 5.2448680956852800e-001 615 | 1.3642717954238290e+000 616 | 4.8203933049125486e-001 617 | -7.8706584502001042e-001 618 | 7.5199926612499590e-001 619 | -1.6688791003091180e-001 620 | -8.1622811056064892e-001 621 | 2.0940651895061930e+000 622 | 8.0152532344038366e-002 623 | -9.3729506929487394e-001 624 | 6.3573877984906246e-001 625 | 1.6820279944331387e+000 626 | 5.9363417229789772e-001 627 | 7.9015287591405581e-001 628 | 1.0525384669901849e-001 629 | -1.5857856161489242e-001 630 | 8.7090745123482771e-001 631 | -1.9475892828364041e-001 632 | 7.5474485412664938e-002 633 | -5.2663484487992240e-001 634 | -6.8548438052366756e-001 635 | -2.6838764878490173e-001 636 | -1.1883459645153542e+000 637 | 2.4857897968336215e-001 638 | 1.0245161722246231e-001 639 | -4.1006876984961096e-002 640 | -2.2475823134718933e+000 641 | -5.1077647633279921e-001 642 | 2.4924264127232151e-001 643 | 3.6919671446379743e-001 644 | 1.7919662051852325e-001 645 | -3.7283412276979996e-002 646 | -1.6033098660032012e+000 647 | 3.3937203890256584e-001 648 | -1.3113481457279527e-001 649 | 4.8518979244871324e-001 650 | 5.9875069775740231e-001 651 | -8.6030886506517967e-002 652 | 3.2529204656648913e-001 653 | -3.3514322960904835e-001 654 | -3.2244920375023883e-001 655 | -3.8237412519474984e-001 656 | -9.5337093281709240e-001 657 | 2.3357559892250851e-001 658 | 1.2352446504741668e+000 659 | -5.7853159974971058e-001 660 | -5.0153736904257773e-001 661 | 7.2286351624396594e-001 662 | 3.9498485331621903e-002 663 | 1.5412787658547042e+000 664 | -1.7010528404698730e+000 665 | -1.0337413076645554e+000 666 | -7.6370763669822572e-001 667 | 2.1764259627156815e+000 668 | 4.3161209992731958e-001 669 | -4.4376518130617915e-001 670 | 2.9995868238615803e-002 671 | -3.1567086967047631e-001 672 | 9.7784570477197974e-001 673 | 1.8294873913410118e-002 674 | 8.1796283374686962e-001 675 | 7.0234110036618524e-001 676 | -2.3127056429901954e-001 677 | -1.1368958008529322e-001 678 | 1.2794051860964067e-001 679 | -7.9940969968013953e-001 680 | -2.3861195623431747e-001 681 | -8.9463237500257545e-002 682 | -1.0232641710863453e+000 683 | 9.3753792337937292e-001 684 | -1.1317192831521843e+000 685 | -7.1070208602827178e-001 686 | -1.1695008619456433e+000 687 | 1.0654371444339836e+000 688 | -6.8039374385658702e-001 689 | -1.7257726569231200e+000 690 | 8.1319959967304112e-001 691 | 1.4418666182923234e+000 692 | 6.7227220216041783e-001 693 | 1.3866495543565135e-001 694 | -8.5953392675766072e-001 695 | -7.5225055816553088e-001 696 | 1.2296150838290758e+000 697 | 1.1507543530981155e+000 698 | -6.0802501127071640e-001 699 | 8.0615791615995780e-001 700 | 2.1713285248001582e-001 701 | -3.7346107032556553e-001 702 | -8.3203043468849469e-001 703 | 2.8686630098358784e-001 704 | -1.8188916235640564e+000 705 | -1.5730514019458928e+000 706 | 2.0156656809047844e+000 707 | -7.1982023978393053e-002 708 | 2.6289094176857488e+000 709 | -2.4331694903778381e-001 710 | 1.7327649426949135e-001 711 | 9.2320707695267612e-001 712 | -1.7855299872084196e-001 713 | -5.2170490682295867e-001 714 | 1.4319619733911875e+000 715 | -8.7011744642428468e-001 716 | 8.0754179199900744e-001 717 | -5.1063464437659145e-001 718 | 7.4351413343903050e-001 719 | 8.4789830498617613e-001 720 | -8.2990071750100802e-001 721 | 5.3299443371653021e-001 722 | 1.0328484132990641e+000 723 | -1.0520239654671704e+000 724 | 3.6211373842305622e-001 725 | -3.6786616879762153e-002 726 | -1.2276355758077513e+000 727 | -2.7509887388406173e-001 728 | -1.6043524146830923e-001 729 | -1.0835748189281726e+000 730 | -1.9542127496674984e+000 731 | -9.0948725759204407e-001 732 | -5.5787276532498651e-003 733 | -1.7234898877785685e+000 734 | 1.2630772536949719e+000 735 | -6.0043337396096219e-001 736 | -2.0639248148829119e+000 737 | 1.1091094017167046e-001 738 | 1.4876142571023079e+000 739 | 5.3002141658683589e-002 740 | 1.6198074381301233e-001 741 | -2.6877918764701345e-002 742 | 1.7357619145408637e-001 743 | 8.8216775480003351e-001 744 | 1.8229441850997191e-001 745 | 7.5529542234764091e-001 746 | 5.0803455271098141e-001 747 | 1.3188014285595623e-001 748 | 2.8010410501918309e-001 749 | -9.8284755553118153e-001 750 | -9.4408743135651363e-001 751 | -1.3057515808979701e-002 752 | 3.5434527592419762e-001 753 | -8.9470882629212700e-001 754 | 8.1211102159521542e-001 755 | 1.0953735238992339e-001 756 | 2.7316439695391792e+000 757 | 4.1107915462951367e-001 758 | -1.3068619689101308e+000 759 | 3.8380649419224561e-001 760 | 4.9950367851879746e-001 761 | -5.1078558701308308e-001 762 | 2.3492204825244120e-001 763 | -5.9782511443613606e-001 764 | 2.0770818548438701e-002 765 | 4.1944275817818127e-001 766 | 1.1911037484264235e+000 767 | 7.7121424508625180e-001 768 | -2.6442219216807445e+000 769 | 2.8542989794149343e-001 770 | 8.2609261897717423e-001 771 | -8.1224925350071864e-003 772 | 8.5843816230125425e-001 773 | 7.7478824003235403e-001 774 | 1.3059453260206879e+000 775 | 1.2315025330368079e+000 776 | 9.5856366647100510e-001 777 | -1.6545476908421763e+000 778 | -9.9039601111699360e-001 779 | 6.8523602244719295e-001 780 | -9.7487001383901362e-001 781 | -6.0672563646930089e-001 782 | 6.8679374136400895e-001 783 | 2.0048856212855626e-002 784 | 1.0638005526661041e+000 785 | -1.3410498594340896e+000 786 | 4.7951043863175041e-001 787 | -1.6339739932203248e+000 788 | -1.4426650201173274e+000 789 | 2.9378142164438520e-001 790 | -1.4036408377460596e-001 791 | -1.1303407455811170e+000 792 | -2.9253805278518674e-001 793 | -5.8253587427217057e-001 794 | -8.9634827661834648e-001 795 | 2.4860108242350701e-001 796 | -1.4896633913508939e+000 797 | 3.1350866229782715e-001 798 | -2.0250844024299690e+000 799 | 5.2898970481903351e-001 800 | 3.4347089930566660e-001 801 | 7.5819260969352720e-001 802 | -6.9194018436655702e-001 803 | 6.8017855208709865e-001 804 | -1.0725410296966313e+000 805 | 8.9977208580063350e-001 806 | -2.1230924008127787e+000 807 | 2.8471227446989472e-001 808 | -7.3332293014127770e-001 809 | -7.7337562913271152e-001 810 | 1.5184172299198212e-001 811 | -3.3684312745845552e-001 812 | 9.7076071773410644e-001 813 | -1.0723635740973697e-001 814 | 1.0134918792483889e+000 815 | -4.7534675820254557e-001 816 | 6.8948145046585918e-002 817 | 3.9859206790517548e-001 818 | 1.1163262352901240e+000 819 | 6.2045112582759088e-001 820 | -2.8767448382835742e-001 821 | -1.3717733303459316e+000 822 | -6.8586843065157310e-001 823 | 3.3168473564598155e-001 824 | -9.9772181574821239e-001 825 | 2.9141809716671352e-001 826 | 1.1070783977551140e+000 827 | 2.4495860662636373e-001 828 | 1.6497577771839117e-001 829 | 4.0623133719069532e-001 830 | 1.2159812073745453e+000 831 | 1.4484243406031581e+000 832 | -1.0251374778499602e+000 833 | 2.0541801449102581e-001 834 | 5.8888218537132087e-001 835 | -2.6402362396244045e-001 836 | 2.4953178015174089e+000 837 | 8.5594766675130296e-001 838 | -8.5095363375518107e-001 839 | 8.1187884281162326e-001 840 | 7.0024171544206504e-001 841 | 7.5993832603664613e-001 842 | -1.7129091965582395e+000 843 | 1.5370212409238098e+000 844 | -1.6098468067955107e+000 845 | 1.1095259898265541e+000 846 | -1.1097040277786727e+000 847 | 3.8546939328107599e-001 848 | 9.6523079343926677e-001 849 | 8.1829722640044333e-001 850 | 3.7048778913385469e-002 851 | -9.2601240026643272e-001 852 | -1.1191866461927766e-001 853 | -8.0302969115052003e-001 854 | -1.6650059447159080e+000 855 | -9.0140060409829148e-001 856 | 5.8834967127102722e-001 857 | 5.5415927545747401e-001 858 | -4.1517260571676179e-001 859 | 6.1794858909707817e-002 860 | 4.5743157052628208e-001 861 | 1.9901391003442651e-001 862 | 2.5755782252888310e-001 863 | 2.0807297566928145e+000 864 | -2.2772365054348027e+000 865 | 3.3902243051720504e-001 866 | 2.8989389059788223e-001 867 | 6.6226085080763075e-001 868 | -5.8086023496557493e-001 869 | 8.8775190575941221e-001 870 | 1.7187104231006892e-001 871 | 8.4882144251976011e-001 872 | 9.6376903452211526e-001 873 | 1.3219179968336130e+000 874 | -6.4344903288135968e-002 875 | 1.3170530854921829e+000 876 | 2.2801732949927683e-001 877 | -1.4296371701761292e+000 878 | -1.4970099649818489e-001 879 | -5.0496755999863963e-001 880 | -1.7291414789403527e+000 881 | -4.1747222271513706e-001 882 | -6.1496852405522484e-001 883 | 7.2077667786711241e-001 884 | 3.3936379316505511e-001 885 | 8.8284508397488570e-001 886 | 2.8424521107906231e-001 887 | -1.4554134604077276e-001 888 | -8.9645900069179191e-002 889 | 2.8916086928940599e-001 890 | 1.1648308451969147e+000 891 | 8.0572934953198672e-001 892 | -1.3556434584711219e+000 893 | 1.2089289677682798e-001 894 | -2.2217791409695326e-001 895 | 5.7173234031556963e-001 896 | -3.0014043090050491e-001 897 | 1.1342768279737556e+000 898 | -1.7935640823670548e-001 899 | -1.4670667021785735e+000 900 | 1.3953457452602691e+000 901 | 4.4083567254596429e-001 902 | 5.6538404630462080e-001 903 | -6.9362259370134161e-001 904 | 8.3386924576935595e-001 905 | -2.2373783926817774e+000 906 | 1.0976440937527501e+000 907 | -1.6169159055030905e-003 908 | -1.6145733022129267e+000 909 | -1.2287267968278146e+000 910 | 2.0740458053173572e-001 911 | 2.2094200106837134e-001 912 | -1.0060730613646314e+000 913 | -4.5306708923047623e-001 914 | 1.3994532653163940e+000 915 | -4.6196398208517120e-001 916 | 3.2715904657580890e-002 917 | 7.9878320069453357e-001 918 | 8.9681578667730510e-001 919 | 1.3789172539834915e-001 920 | -1.6191464403215912e+000 921 | -1.6466057274160639e+000 922 | 4.2870687800299895e-001 923 | -7.3723083513283427e-001 924 | 5.6492614088060311e-001 925 | -1.3841666813001243e+000 926 | 4.6026798815136738e-001 927 | 6.2938364836052341e-001 928 | 3.7984731378064607e-001 929 | -1.0133298560563964e+000 930 | -3.4724278219726917e-001 931 | 4.4191230168808343e-001 932 | -1.5902402927199464e+000 933 | -7.0141670643851983e-001 934 | -1.0776006447446453e+000 935 | 1.0022196791535878e+000 936 | 1.7294805125560682e+000 937 | 7.0903220640580455e-001 938 | -7.4789686282304302e-001 939 | 2.2886238629630734e-001 940 | -2.2349661477433927e-001 941 | -8.5327526169915158e-001 942 | 3.4562680245290039e-001 943 | 1.0976448076542263e-001 944 | -1.1330389534183765e+000 945 | -6.8312354290510657e-001 946 | -2.7785622825393874e-001 947 | 6.5478985350402708e-001 948 | -1.2483940465541046e+000 949 | -5.9753903083554050e-001 950 | -4.8181254767985610e-001 951 | 9.8337216907855596e-001 952 | 1.7621206749905134e+000 953 | 1.4274016599502681e+000 954 | 9.1176303296658290e-001 955 | 3.2682265313959347e-001 956 | 6.9618539606094362e-002 957 | -1.4997626510648001e+000 958 | -4.1822319072283992e-001 959 | -2.1036797628566622e-002 960 | 2.2842453001480714e-001 961 | -1.0081957898310381e+000 962 | -6.6462216518604644e-001 963 | 5.5817657783340446e-001 964 | -1.1885420587449229e+000 965 | -7.7548149842735314e-001 966 | 2.7104207413491849e-001 967 | 1.5349756540521917e+000 968 | -1.0522826869959245e+000 969 | 6.2555857129595516e-001 970 | -7.9762607239545380e-001 971 | -3.1352199144516135e-001 972 | -6.0220975336174298e-001 973 | 1.2590603229803499e+000 974 | 8.5848425475690193e-001 975 | -2.1052918773712550e+000 976 | -3.6093718087471605e-001 977 | 5.5355672422988844e-001 978 | -1.5563838437959394e+000 979 | -2.0666572232414504e-001 980 | -4.2556754578906064e-001 981 | 4.9377824516667551e-001 982 | -8.7090761096057057e-001 983 | 7.9827657539909697e-002 984 | -5.2161913924699599e-001 985 | -1.4138608773298842e+000 986 | -3.8429318184067363e-001 987 | -4.5792221533766159e-001 988 | -2.9147068743054511e-001 989 | -3.0122401342776561e-001 990 | -1.5885937989765286e+000 991 | 1.0942866617012115e+000 992 | 1.3241668585743984e+000 993 | -1.2647962573582100e-001 994 | -7.3716381545633602e-001 995 | 2.1371883726268484e-001 996 | -4.0052913427999903e-001 997 | 6.4937746557551440e-002 998 | -1.7579955918808270e+000 999 | 1.6867480239810837e+000 1000 | 3.2740020845304707e-001 1001 | 7.1596676107629520e-001 1002 | 1.5986479107064766e+000 1003 | -2.0647409060685060e+000 1004 | -7.4363164216871047e-001 1005 | 1.7618450099389210e-001 1006 | 5.2783883161400624e-001 1007 | -5.5315262898841255e-001 1008 | 2.9827984302880528e-001 1009 | -1.2266067996960999e+000 1010 | -1.8967608463762181e-001 1011 | -3.0171330830382392e-001 1012 | 9.5695595342932738e-001 1013 | -5.3336587320889761e-001 1014 | -9.0108181507233853e-001 1015 | -8.9255153659802255e-001 1016 | 2.7871651481178417e-001 1017 | -7.4580671010209010e-001 1018 | 1.6034635144509726e+000 1019 | 5.7426961912348051e-001 1020 | 3.2065460206679214e-001 1021 | -1.5138296917491015e-001 1022 | 3.1576218522755861e-001 1023 | 1.3437026075311818e+000 1024 | -2.2378319603447947e+000 1025 | -------------------------------------------------------------------------------- /tests/test_embedded_sequence.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | import unittest 3 | 4 | from pyeeg import embed_seq 5 | 6 | 7 | class EmbeddedSequenceTests(unittest.TestCase): 8 | def setUp(self): 9 | self.data = range(0, 9) 10 | 11 | def test_embedded_sequence_1_4(self): 12 | self.assertEqual( 13 | embed_seq(self.data, 1, 4).all(), 14 | numpy.asarray( 15 | [ 16 | [0., 1., 2., 3.], 17 | [1., 2., 3., 4.], 18 | [2., 3., 4., 5.], 19 | [3., 4., 5., 6.], 20 | [4., 5., 6., 7.], 21 | [5., 6., 7., 8.] 22 | ] 23 | ).all() 24 | ) 25 | 26 | def test_embedded_sequence_2_3(self): 27 | self.assertEqual( 28 | embed_seq(self.data, 2, 3).all(), 29 | numpy.asarray( 30 | [ 31 | [0., 2., 4.], 32 | [1., 3., 5.], 33 | [2., 4., 6.], 34 | [3., 5., 7.], 35 | [4., 6., 8.] 36 | ] 37 | ).all() 38 | ) 39 | 40 | def test_embedded_sequence_4_1(self): 41 | self.assertEqual( 42 | embed_seq(self.data, 2, 3).all(), 43 | numpy.asarray( 44 | [ 45 | [0.], 46 | [1.], 47 | [2.], 48 | [3.], 49 | [4.], 50 | [5.], 51 | [6.], 52 | [7.], 53 | [8.] 54 | ] 55 | ).all() 56 | ) 57 | 58 | 59 | if __name__ == '__main__': 60 | unittest.main() 61 | -------------------------------------------------------------------------------- /tests/test_information_based_similarity.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from pyeeg import information_based_similarity 4 | 5 | 6 | class InformationBasedSimilarityTests(unittest.TestCase): 7 | def test_information_based_similarity(self): 8 | x_axis_data = [ 9 | 0.16098749, 0.17692958, -1.81950537, 0.33561288, 0.40291009, 10 | -0.13148819, -1.21536256, -1.08481235, -0.21487062, -0.81384572, 11 | 0.49025693, -0.95941054, -0.5643706, -1.19146385, 1.04563275, 12 | -0.31872928, 0.56111021, 1.87073953, -1.28776991, -0.7751325, 13 | 0.30841261, -1.15163104, 0.79371283, 2.24722208, -0.93464575, 14 | -0.66843521, 0.5917969, 0.77809267, 0.55931622, -1.39641768, 15 | 1.58531242, 0.58656892, -0.31532364, 0.13598254, -0.53946447, 16 | -1.49558044, -0.63693475, 1.29578787, -0.13373468, -1.03400281, 17 | -0.67983219, 0.16221873, 1.53821019, -0.11938391, 1.21657004, 18 | -0.1920458, 1.40564056, 1.15128355, -0.33193437, 1.29209686, 19 | 1.04658007, 0.04220999, 1.27969761, 0.22240636, -1.02273562, 20 | -1.28145474, -1.73571824, -0.3166042, 0.46752785, -0.62505572, 21 | 0.7890322, 1.5252607, -0.13748426, -1.95247665, -0.05956672, 22 | -0.28094525, -1.9678474, 0.19124261, -0.39106891, -0.56257509, 23 | -0.32465297, -1.62583327, -0.3542932, -0.64414968, -0.65452741, 24 | 0.37574931, -0.49688922, -0.07037562, -2.05893691, 0.06086633, 25 | -0.54422023, -0.54132022, -0.70246688, 0.12909285, 0.56746142, 26 | 0.45833448, -0.7760291, -1.98159666, 0.69102227, -0.37879553, 27 | -1.77152359, -1.09826121, 0.60743068, -0.80848143, 1.36366829, 28 | -1.22787525, -0.21834009, -0.62767535, -0.97495622, 1.84789436 29 | ] 30 | 31 | y_axis_data = [ 32 | -0.25445107, -0.60882641, -0.77998597, -0.57995904, 1.64100167, 33 | -1.60364241, 1.70536049, 0.31079375, 0.99108882, -2.9507694, 34 | -1.26561011, -0.20977681, -2.41021991, -0.5247534, -0.09417403, 35 | 1.88258898, -2.18559031, 1.62417099, 0.76095466, 0.30148008, 36 | 1.34264681, -0.60959223, 0.11269381, 0.75072293, -0.01133381, 37 | 1.29521933, -0.49596373, 0.08015857, -0.63720742, -0.63689909, 38 | -0.40723797, 0.05403306, 1.54368196, 0.64176921, -1.20655783, 39 | -1.09622567, 1.83186385, 0.61029403, -0.80470078, 0.29027348, 40 | -0.67167157, 0.96395387, -0.5710966, 0.23083643, -0.02464553, 41 | 0.51964705, 0.22153853, -0.43861145, 0.57767866, -2.50709032, 42 | 0.56876212, -0.05799226, -0.85173653, -0.61042222, 1.31170402, 43 | -0.31291646, -0.44432741, -0.7150911, 0.80983862, -0.89431059, 44 | 0.70870062, 1.36517003, 0.15736342, -0.03805528, 0.51892929, 45 | 1.24219431, -0.94921759, 2.10609206, -0.58696224, -1.33394959, 46 | 0.00510772, 0.2709552, -0.08236258, -2.4057175, -1.26220379, 47 | 0.72681967, 0.41556896, -0.3481339, -0.74691867, 0.8221449, 48 | 0.62641517, -1.04556923, -0.83185258, 0.77643477, 0.06690493, 49 | -0.22541358, -0.57588397, 0.29827298, 1.27063634, -1.26317499, 50 | 1.73526005, -1.05339668, -0.94503578, 0.28044202, 0.83457606, 51 | 0.3705322, -0.96882525, 0.30503691, -0.71220423, 0.49516661 52 | ] 53 | 54 | self.assertEqual( 55 | information_based_similarity(x_axis_data, y_axis_data, 8), 56 | 0.50445013843666031 57 | ) 58 | 59 | 60 | if __name__ == '__main__': 61 | unittest.main() 62 | -------------------------------------------------------------------------------- /tests/test_largest_lyauponov_exponent.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | import unittest 3 | 4 | from pyeeg import LLE 5 | 6 | 7 | class LLETests(unittest.TestCase): 8 | def test_largest_lyauponov_exponent(self): 9 | data = numpy.asarray([3, 4, 1, 2, 4, 51, 4, 32, 24, 12, 3, 45]) 10 | 11 | self.assertAlmostEqual( 12 | LLE(data, 2, 4, 1, 1), 13 | 0.18771136179353307, 14 | places=12 15 | ) 16 | 17 | 18 | if __name__ == '__main__': 19 | unittest.main() 20 | -------------------------------------------------------------------------------- /tests/test_permutation_entropy.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | import unittest 3 | 4 | from pyeeg import permutation_entropy 5 | 6 | 7 | class PermutationEntropyTests(unittest.TestCase): 8 | def test_permutation_entropy(self): 9 | data = numpy.asarray([1, 2, 4, 5, 12, 3, 4, 5]) 10 | 11 | self.assertEqual( 12 | permutation_entropy(data, 5, 1), 13 | 2.0 14 | ) 15 | 16 | 17 | if __name__ == '__main__': 18 | unittest.main() 19 | -------------------------------------------------------------------------------- /tests/test_sampen.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | import os 3 | import unittest 4 | 5 | from pyeeg import samp_entropy 6 | 7 | 8 | class SampEnTests(unittest.TestCase): 9 | def test_sampen_against_predictable_sequence(self): 10 | data = numpy.asarray([10, 20] * 2000) 11 | self.assertAlmostEqual( 12 | samp_entropy(data, 2, 0.2), 13 | 0.0, 14 | places=2 15 | ) 16 | 17 | def test_sampen_against_original_c_test_data(self): 18 | """Use test data from 19 | http://www.physionet.org/physiotools/sampen/c/sampentest.txt 20 | """ 21 | dir = os.path.dirname(__file__) 22 | file_path = os.path.join(dir, './demo_data/sampentest.txt') 23 | data = [] 24 | with open(file_path, 'r') as file: 25 | for row in file: 26 | data.append(float(row.strip())) 27 | 28 | self.assertEqual( 29 | samp_entropy(numpy.asarray(data), 2, 0.2), 30 | 2.1233284920357112 31 | ) 32 | 33 | 34 | if __name__ == '__main__': 35 | unittest.main() 36 | --------------------------------------------------------------------------------