-
Notifications
You must be signed in to change notification settings - Fork 6
/
embed.py
58 lines (49 loc) · 1.63 KB
/
embed.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
###############################################################################
#
# CSCI 4446 - Chaotic Dynamics
#
# File: embed.py
# Author: Ken Sheedlo
#
# Delay coordinate embedding.
#
###############################################################################
from __future__ import division
import numpy
import chaostest
import unittest
def embed(xs, delay, dim):
'''
Embeds the X data and produces the corresponding trajectory.
Parameters:
xs The data set to embed, as an (nx1) vector. Must be sampled with
an evenly spaced interval.
delay The time interval to span, as an integer multiple of the
sampling interval.
dim The dimension of the embed vectors.
Returns:
vs An (n x dim) ndarray, where vs[i,j] = $\\theta$(t_j + i*delay).
'''
return numpy.array([
xs[j:j+(dim*delay):delay] for j in xrange(len(xs)-(dim*delay)+1)
], dtype=numpy.float64)
class TestEmbed(chaostest.TestCase):
'''
Test suite for delay coordinate embedding module.
'''
def test_embed(self):
'''
Tests embed function under normal operation.
'''
xs = numpy.array(range(1, 8), dtype=numpy.float64)
result = embed(xs, 2, 3)
expected = numpy.array([
[1, 3, 5],
[2, 4, 6],
[3, 5, 7]
], dtype=numpy.float64)
for (rrow, xrow) in zip(result, expected):
for (r, x) in zip(rrow, xrow):
self.assertEquals(r, x)
if __name__ == "__main__":
unittest.main()