-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathps10.py
148 lines (132 loc) · 4.95 KB
/
ps10.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
###############################################################################
#
# CSCI 4446 - Chaotic Dynamics
# File: ps10.py
# Author: Ken Sheedlo
#
# Leap-Nanosecond Observation Prediction
#
###############################################################################
from __future__ import division
import dimension
import getopt
import lorenz
import numpy
import plot
import rungekutta
import sys
import tispy
from ps9 import first_min
from utils import suffixed, mod2pi
def find_loglog_slope(xs, x0, file_prefix=None):
epss = numpy.array([(2 ** x) for x in xrange(10, -18, -1)], dtype=numpy.float64)
ds = dimension.capacity(xs, x0, epss)
plot.loglog(ds[:,0], ds[:,1])
lbound = numpy.float64(raw_input('Choose a lower bound: '))
ubound = numpy.float64(raw_input('Choose an upper bound: '))
iss = [i for (i, d) in enumerate(ds[:,0]) if lbound <= d and d <= ubound]
i_low = iss[0]
i_hi = iss[-1] + 1
ds_eslice = numpy.log(ds[i_low:i_hi,0])
ds_nslice = numpy.log(ds[i_low:i_hi,1])
ps = numpy.polyfit(ds_eslice, ds_nslice, 1)
def _render(axes):
axes.loglog(ds[:,0], ds[:,1])
axes.loglog([lbound, lbound], axes.get_ybound(), 'k')
axes.loglog([ubound, ubound], axes.get_ybound(), '#414243')
(lne, hne) = axes.get_ybound()
lx = ((numpy.e ** (-ps[1])) * lne) ** (1/ps[0])
hx = ((numpy.e ** (-ps[1])) * hne) ** (1/ps[0])
axes.loglog([lx, hx], [lne, hne], 'k--')
axes.legend((
r'$N(\varepsilon)$',
'Lower scaling bound',
'Upper scaling bound',
'Linear fit'
), loc=4)
plot.render(
title=r'Capacity Dimension $D_c = {0}$'.format(ps[0]),
xlabel=r'$\frac{1}{\varepsilon}$',
ylabel=r'$N(\varepsilon)$',
ax_callback=_render,
file_prefix=file_prefix
)
return ps[0]
def pr2a(file_prefix=None):
lfunc = lorenz.lorenz(16, 45, 4)
ts, xxs = rungekutta.rk4(
lfunc,
0.0,
numpy.array([-13.0, -12.0, 52.0], dtype=numpy.float64),
0.0001,
300000
)
xs = xxs.transpose()[:,0]
data = numpy.array(zip(xs, ts), dtype=numpy.float64)
ms = tispy.mutual('-D', 16000, input=data)
tau = first_min(ms)
ws = tispy.delay('-d', int(tau), '-m', 7, input=data)
x0 = numpy.array([-35, -35], dtype=numpy.float64)
zs = numpy.array(zip(ws[100000:,0], ws[100000:,5]), dtype=numpy.float64)
d_cap = find_loglog_slope(zs, x0, file_prefix=suffixed(file_prefix, '_2a'))
print 'Lorenz\tembed\td_cap = {0:.6f}'.format(d_cap)
def pr2b(file_prefix=None):
lfunc = lorenz.lorenz(16, 45, 4)
ts, xxs = rungekutta.rk4(
lfunc,
0.0,
numpy.array([-13.0, -12.0, 52.0], dtype=numpy.float64),
0.0001,
1000000
)
xs = xxs.transpose()
x0 = numpy.array([-30, -40, 4], dtype=numpy.float64)
d_cap = find_loglog_slope(xs[100000:400000,:], x0, file_prefix=suffixed(file_prefix, '_2b'))
print 'Lorenz\tshort\td_cap = {0:.6f}'.format(d_cap)
return xs
def pr2c(xs, file_prefix=None):
x0 = numpy.array([-30, -40, 4], dtype=numpy.float64)
d_cap = find_loglog_slope(xs[100000:,:], x0, file_prefix=suffixed(file_prefix, '_2c'))
print 'Lorenz\tlong\td_cap = {0:.6f}'.format(d_cap)
def extrema():
lfunc = lorenz.lorenz(16, 45, 4)
ts, xxs = rungekutta.rk4(
lfunc,
0.0,
numpy.array([-13.0, -12.0, 52.0], dtype=numpy.float64),
0.0001,
300000
)
xs = xxs.transpose()[:,0]
data = numpy.array(zip(xs, ts), dtype=numpy.float64)
ms = tispy.mutual('-D', 16000, input=data)
tau = first_min(ms)
print 'Tau: {0:.6f}'.format(tau)
ws = tispy.delay('-d', int(tau), '-m', 7, input=data)
zs = ws[100000:,:]
mins = numpy.empty(7, dtype=numpy.float64)
maxs = numpy.empty(7, dtype=numpy.float64)
for i in xrange(7):
mins[i] = min(zs[:,i])
maxs[i] = max(zs[:,i])
print 'Mins: {0}'.format(mins)
print 'Maxs: {0}'.format(maxs)
def main(argv=None):
if argv is None:
argv = sys.argv
file_prefix = None
try:
options, args = getopt.getopt(argv[1:], 'f:')
for opt, arg in options:
if opt == '-f':
file_prefix = arg
except getopt.GetoptError as err:
print str(err)
return 2
# pr2a(file_prefix=file_prefix)
# pr2b(file_prefix=file_prefix)
# pr2c(file_prefix=file_prefix)
pr2c(pr2b(file_prefix=file_prefix), file_prefix=file_prefix)
return 0
if __name__ == "__main__":
sys.exit(main())