def pr1(file_prefix): df = threebody(1.0, 0.5, 0.5, 0.5) x0 = numpy.array([0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 3000, 0, 0, 0, 0], dtype=numpy.float64) ts, xs = rungekutta.rk4(df, 0, x0, 0.005, 7600) xs = xs.transpose() plot.render(xs[:, 0], xs[:, 1], 'b', xs[:, 6], xs[:, 7], 'r', xs[:, 12], xs[:, 13], 'g', xlabel='x (normalized AU)', ylabel='y (normalized AU)', xbound=(-10.0, 10.0), ybound=(0.0, 20.0), aspect='equal', title='3-body Orbital Trajectory', legend=('Star A', 'Star B'), file_prefix=suffixed(file_prefix, '_1a')) plot.render(xs[:, 6] - xs[:, 0], xs[:, 7] - xs[:, 1], 'r', xlabel='x (normalized AU)', ylabel='y (normalized AU)', aspect='equal', title='3-body Trajectory, Star A at origin', legend=('Star B', ), file_prefix=suffixed(file_prefix, '_1b'))
def pr1(file_prefix): df = threebody(1.0, 0.5, 0.5, 0.5) x0 = numpy.array([ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 3000, 0, 0, 0, 0 ], dtype=numpy.float64) ts, xs = rungekutta.rk4(df, 0, x0, 0.005, 7600) xs = xs.transpose() plot.render(xs[:,0], xs[:,1], 'b', xs[:,6], xs[:,7], 'r', xs[:,12], xs[:,13], 'g', xlabel='x (normalized AU)', ylabel='y (normalized AU)', xbound=(-10.0, 10.0), ybound=(0.0, 20.0), aspect='equal', title='3-body Orbital Trajectory', legend=('Star A', 'Star B'), file_prefix=suffixed(file_prefix, '_1a') ) plot.render(xs[:,6] - xs[:,0], xs[:,7] - xs[:,1], 'r', xlabel='x (normalized AU)', ylabel='y (normalized AU)', aspect='equal', title='3-body Trajectory, Star A at origin', legend=('Star B',), file_prefix=suffixed(file_prefix, '_1b') )
def pr2(file_prefix): df = threebody(1.0, 0.5, 0.5, 0.5) x0 = numpy.array( [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 20, 0, 0, -0.15, 0], dtype=numpy.float64) ts, xs = rungekutta.rk4(df, 0, x0, 0.005, 50000) xs = xs.transpose() plot.render(xs[:5500, 0], xs[:5500, 1], 'b', xs[:5500, 6], xs[:5500, 7], 'r', xs[:5500, 12], xs[:5500, 13], 'g', xlabel='x (normalized AU)', ylabel='y (normalized AU)', title='3-body Orbital Interaction', legend=('Star A', 'Star B', 'Star C'), file_prefix=suffixed(file_prefix, '_2a')) plot.render(xs[:, 0], xs[:, 1], 'b', xs[:, 12], xs[:, 13], 'g', xlabel='x (normalized AU)', ylabel='y (normalized AU)', title='3-body Orbital Interaction', legend=('Star A', 'Star C'), file_prefix=suffixed(file_prefix, '_2b'))
def pr2(file_prefix): df = threebody(1.0, 0.5, 0.5, 0.5) x0 = numpy.array([ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 20, 0, 0, -0.15, 0 ], dtype=numpy.float64) ts, xs = rungekutta.rk4(df, 0, x0, 0.005, 50000) xs = xs.transpose() plot.render(xs[:5500,0], xs[:5500,1], 'b', xs[:5500,6], xs[:5500,7], 'r', xs[:5500,12], xs[:5500,13], 'g', xlabel='x (normalized AU)', ylabel='y (normalized AU)', title='3-body Orbital Interaction', legend=('Star A', 'Star B', 'Star C'), file_prefix=suffixed(file_prefix, '_2a') ) plot.render(xs[:,0], xs[:,1], 'b', xs[:,12], xs[:,13], 'g', xlabel='x (normalized AU)', ylabel='y (normalized AU)', title='3-body Orbital Interaction', legend=('Star A', 'Star C'), file_prefix=suffixed(file_prefix, '_2b') )
def pr2b(file_prefix, delay, dim): embed_run( dset='data3', delay=delay, vdim=dim, ydim=5, file_prefix=suffixed(file_prefix, '_2b') )
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 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 pr1(file_prefix=None): data = numpy.loadtxt('data/ps8/data1', dtype=numpy.float64) points = construct_angular_velocity(data[::30, 1], data[::30, 0]) thetas = numpy.array([pendulum.mod2pi(theta) for theta in points[:, 1]], dtype=numpy.float64) plot.render(thetas, points[:, 2], 'b', xlabel=r'$\theta$', ylabel=r'$\omega$', title='State-space Trajectory, Data Set 1', file_prefix=suffixed(file_prefix, '_1'))
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 pr1(file_prefix=None): data = numpy.loadtxt('data/ps8/data1', dtype=numpy.float64) points = construct_angular_velocity(data[::30,1], data[::30,0]) thetas = numpy.array([ pendulum.mod2pi(theta) for theta in points[:,1] ], dtype=numpy.float64) plot.render( thetas, points[:,2], 'b', xlabel=r'$\theta$', ylabel=r'$\omega$', title='State-space Trajectory, Data Set 1', file_prefix=suffixed(file_prefix, '_1') )
def pr4(file_prefix=None): data = numpy.loadtxt("data/ps8/data2.first250sec", dtype=numpy.float64) vs = tispy.delay("-d", "155", "-m", "8", input=data) plot.embedded( vs, 0, 2, "k.", markersize=0.6, ybound=(0, 2 * numpy.pi), yticks=(0, numpy.pi / 2, numpy.pi, 3 * numpy.pi / 2, 2 * numpy.pi), yticklabels=("0", r"$\frac{\pi}{2}$", r"$\pi$", r"$\frac{3\pi}{2}$", r"$2\pi$"), title=r"Delay Coordinate Embedding: {0}, $\tau={1}$ s".format("data2", _get_actual_delay("data2", 1, 155)), xlabel=r"$\theta(t + {0})$".format(_get_actual_delay("data2", 0, 155)), ylabel=r"$\theta(t + {0})$".format(_get_actual_delay("data2", 2, 155)), aspect="equal", file_prefix=suffixed(file_prefix, "_3"), )
def pr3(file_prefix=None): data = numpy.loadtxt("data/ps8/data2.first250sec", dtype=numpy.float64) fnns = tispy.false_nearest("-M", "1,10", "-d", "155", input=data) dim = select_embedding_dimension(fnns) def _render(axes): axes.plot(fnns[:, 0], fnns[:, 1]) axes.plot([dim, dim], axes.get_ybound(), "k") axes.plot(axes.get_xbound(), [0.1, 0.1], "k--") axes.legend(("False nearest neighbors", r"Selected $m$", r"$\leq$10% FNNs required")) plot.render( xlabel=r"$m$", ylabel="Fraction of false nearest neighbors", title=r"False nearest neighbors vs. embedding dimension ($m$={0})".format(select_embedding_dimension(fnns)), ax_callback=_render, file_prefix=suffixed(file_prefix, "_2"), )
def pr5(dim=8, file_prefix=None): data = numpy.loadtxt('data/ps8/data2', dtype=numpy.float64) ms = tispy.lyap_k('-d', 155, '-m', dim, '-M', dim, input=data) pargs = cut(ms[:, 0], ms[:, 1]) # Find the average slope of the first two points. total = 0.0 count = len(pargs) / 2 for i in xrange(0, len(pargs), 2): [x1, x2] = pargs[i][:2] [y1, y2] = pargs[i + 1][:2] total += (y2 - y1) / (0.31 * (x2 - x1)) print 'Found Lyapunov exponent: {0:.6f}'.format(total / count) plot.render(*pargs, xlabel='Iterations', ylabel='Logarithm of the Stretching Factor', title='Calculating the Lyapunov Exponent', file_prefix=suffixed(file_prefix, '_4'))
def pr4(file_prefix): """This is not the problem you are looking for.""" x0 = numpy.array([ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 21.5, 0, 0, -0.15, 0 ], dtype=numpy.float64) ts, xs = rungekutta.rk4(df, 0, x0, 0.005, 8000) xs = xs.transpose() plot.render(xs[:,0], xs[:,1], 'b', xs[:,6], xs[:,7], 'r', xs[:,12], xs[:,13], 'g', xlabel='x (normalized AU)', ylabel='y (normalized AU)', title=r'3-body Orbital Interaction ($x_{14}=21.5$)', legend=('Star A', 'Star B', 'Star C'), file_prefix=suffixed(file_prefix, '_4') )
def pr3(file_prefix=None): data = numpy.loadtxt('data/ps8/data2.first250sec', dtype=numpy.float64) fnns = tispy.false_nearest('-M', '1,10', '-d', '155', input=data) dim = select_embedding_dimension(fnns) def _render(axes): axes.plot(fnns[:, 0], fnns[:, 1]) axes.plot([dim, dim], axes.get_ybound(), 'k') axes.plot(axes.get_xbound(), [0.1, 0.1], 'k--') axes.legend(('False nearest neighbors', r'Selected $m$', r'$\leq$10% FNNs required')) plot.render( xlabel=r'$m$', ylabel='Fraction of false nearest neighbors', title=r'False nearest neighbors vs. embedding dimension ($m$={0})'. format(select_embedding_dimension(fnns)), ax_callback=_render, file_prefix=suffixed(file_prefix, '_2'))
def pr4(file_prefix=None): data = numpy.loadtxt('data/ps8/data2.first250sec', dtype=numpy.float64) vs = tispy.delay('-d', '155', '-m', '8', input=data) plot.embedded( vs, 0, 2, 'k.', markersize=0.6, ybound=(0, 2 * numpy.pi), yticks=(0, numpy.pi / 2, numpy.pi, 3 * numpy.pi / 2, 2 * numpy.pi), yticklabels=('0', r'$\frac{\pi}{2}$', r'$\pi$', r'$\frac{3\pi}{2}$', r'$2\pi$'), title=r'Delay Coordinate Embedding: {0}, $\tau={1}$ s'.format( 'data2', _get_actual_delay('data2', 1, 155)), xlabel=r'$\theta(t + {0})$'.format(_get_actual_delay('data2', 0, 155)), ylabel=r'$\theta(t + {0})$'.format(_get_actual_delay('data2', 2, 155)), aspect='equal', file_prefix=suffixed(file_prefix, '_3'))
def pr3(file_prefix): ic = lambda y: numpy.array([ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, y, 0, 0, -0.15, 0 ], dtype=numpy.float64) df = threebody(1.0, 0.5, 0.5, 0.5) for i in xrange(8): ts, xs = rungekutta.rk4(df, 0, ic(0.3*i + 20.0), 0.005, 8000) xs = xs.transpose() plot.render(xs[:,0], xs[:,1], 'b', xs[:,6], xs[:,7], 'r', xs[:,12], xs[:,13], 'g', xlabel='x (normalized AU)', ylabel='y (normalized AU)', title=r'3-body Orbital Interaction ($x_{14}=%.1f$)' % (0.3*i+20.0), legend=('Star A', 'Star B', 'Star C'), file_prefix=suffixed(file_prefix, '_3{0}'.format(chr(97+i))) )
def pr4(file_prefix): """This is not the problem you are looking for.""" x0 = numpy.array( [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 21.5, 0, 0, -0.15, 0], dtype=numpy.float64) ts, xs = rungekutta.rk4(df, 0, x0, 0.005, 8000) xs = xs.transpose() plot.render(xs[:, 0], xs[:, 1], 'b', xs[:, 6], xs[:, 7], 'r', xs[:, 12], xs[:, 13], 'g', xlabel='x (normalized AU)', ylabel='y (normalized AU)', title=r'3-body Orbital Interaction ($x_{14}=21.5$)', legend=('Star A', 'Star B', 'Star C'), file_prefix=suffixed(file_prefix, '_4'))
def pr2(delay=None, file_prefix=None): data = numpy.loadtxt("data/ps8/data2.first250sec", dtype=numpy.float64) if delay is not None: ms = tispy.mutual("-D", str(delay), input=data) else: ms = tispy.mutual(input=data) tau = first_min(ms) def _render(axes): axes.plot(ms[:, 0], ms[:, 1]) (lbound, ubound) = axes.get_ybound() axes.plot([tau, tau], [lbound, ubound], "k") axes.legend(("Mutual information", r"Optimal $\tau$")) plot.render( xlabel=r"$\tau$", ylabel="Mutual information", title=r"Mutual information vs. $\tau$ (min at $\tau$={0})".format(first_min(ms)), ax_callback=_render, file_prefix=suffixed(file_prefix, "_1"), )
def pr2(delay=None, file_prefix=None): data = numpy.loadtxt('data/ps8/data2.first250sec', dtype=numpy.float64) if delay is not None: ms = tispy.mutual('-D', str(delay), input=data) else: ms = tispy.mutual(input=data) tau = first_min(ms) def _render(axes): axes.plot(ms[:, 0], ms[:, 1]) (lbound, ubound) = axes.get_ybound() axes.plot([tau, tau], [lbound, ubound], 'k') axes.legend(('Mutual information', r'Optimal $\tau$')) plot.render( xlabel=r'$\tau$', ylabel='Mutual information', title=r'Mutual information vs. $\tau$ (min at $\tau$={0})'.format( first_min(ms)), ax_callback=_render, file_prefix=suffixed(file_prefix, '_1'))
def pr5(dim=8, file_prefix=None): data = numpy.loadtxt("data/ps8/data2", dtype=numpy.float64) ms = tispy.lyap_k("-d", 155, "-m", dim, "-M", dim, input=data) pargs = cut(ms[:, 0], ms[:, 1]) # Find the average slope of the first two points. total = 0.0 count = len(pargs) / 2 for i in xrange(0, len(pargs), 2): [x1, x2] = pargs[i][:2] [y1, y2] = pargs[i + 1][:2] total += (y2 - y1) / (0.31 * (x2 - x1)) print "Found Lyapunov exponent: {0:.6f}".format(total / count) plot.render( *pargs, xlabel="Iterations", ylabel="Logarithm of the Stretching Factor", title="Calculating the Lyapunov Exponent", file_prefix=suffixed(file_prefix, "_4") )
def pr6(file_prefix=None): lfunc = lorenz.lorenz(16, 45, 4) ts, vs = rungekutta.rk4(lfunc, 0.0, numpy.array([-13.0, -12.0, 52.0], dtype=numpy.float64), 0.001, 30000) xs = vs.transpose()[:, 0] data = numpy.array(zip(xs, ts), dtype=numpy.float64) ms = tispy.mutual("-D", 1600, input=data) tau = first_min(ms) ws = tispy.delay("-d", int(tau), "-m", 7, input=data) col1 = 0 col2 = 5 plot.render( ws[:, col1], ws[:, col2], "k.", markersize=0.6, title=r"Delay Coordinate Embedding: {0}, $\tau={1}$ s".format(r"lorenz", 0.001 * tau), xlabel=r"$x(t+{0:.3f})$".format(col1 * 0.001 * tau), ylabel=r"$x(t+{0:.3f})$".format(col2 * 0.001 * tau), file_prefix=suffixed(file_prefix, "_6"), ) return tau
def pr6(file_prefix=None): lfunc = lorenz.lorenz(16, 45, 4) ts, vs = rungekutta.rk4( lfunc, 0.0, numpy.array([-13.0, -12.0, 52.0], dtype=numpy.float64), 0.001, 30000) xs = vs.transpose()[:, 0] data = numpy.array(zip(xs, ts), dtype=numpy.float64) ms = tispy.mutual('-D', 1600, input=data) tau = first_min(ms) ws = tispy.delay('-d', int(tau), '-m', 7, input=data) col1 = 0 col2 = 5 plot.render(ws[:, col1], ws[:, col2], 'k.', markersize=0.6, title=r'Delay Coordinate Embedding: {0}, $\tau={1}$ s'.format( r'lorenz', 0.001 * tau), xlabel=r'$x(t+{0:.3f})$'.format(col1 * 0.001 * tau), ylabel=r'$x(t+{0:.3f})$'.format(col2 * 0.001 * tau), file_prefix=suffixed(file_prefix, '_6')) return tau
def pr6x1(tau, file_prefix=None): lfunc = lorenz.lorenz(16, 45, 4) ts, vs = rungekutta.rk4(lfunc, 0.0, numpy.array([-13.0, -12.0, 52.0], dtype=numpy.float64), 0.001, 30000) xs = vs.transpose()[:, 0] data = numpy.array(zip(xs, ts), dtype=numpy.float64) ms = tispy.lyap_k("-d", int(tau), "-m", 7, "-M", 7, input=data) pargs = cut(ms[:, 0], ms[:, 1]) total = 0.0 count = len(pargs) / 2 for i in xrange(0, len(pargs), 2): xs = 0.31 * pargs[i][:50] ys = pargs[i + 1][:50] ps = numpy.polyfit(xs, ys, 1) total += ps[0] print "Lorenz lyapunov exponent: {0}".format(total / count) plot.render( *pargs, xlabel="Iterations", ylabel="Logarithm of the Stretching Factor", title="Calculating the Lyapunov Exponent", file_prefix=suffixed(file_prefix, "_7") )
def pr6x1(tau, file_prefix=None): lfunc = lorenz.lorenz(16, 45, 4) ts, vs = rungekutta.rk4( lfunc, 0.0, numpy.array([-13.0, -12.0, 52.0], dtype=numpy.float64), 0.001, 30000) xs = vs.transpose()[:, 0] data = numpy.array(zip(xs, ts), dtype=numpy.float64) ms = tispy.lyap_k('-d', int(tau), '-m', 7, '-M', 7, input=data) pargs = cut(ms[:, 0], ms[:, 1]) total = 0.0 count = len(pargs) / 2 for i in xrange(0, len(pargs), 2): xs = 0.31 * pargs[i][:50] ys = pargs[i + 1][:50] ps = numpy.polyfit(xs, ys, 1) total += ps[0] print 'Lorenz lyapunov exponent: {0}'.format(total / count) plot.render(*pargs, xlabel='Iterations', ylabel='Logarithm of the Stretching Factor', title='Calculating the Lyapunov Exponent', file_prefix=suffixed(file_prefix, '_7'))
def pr3(file_prefix): ic = lambda y: numpy.array( [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, y, 0, 0, -0.15, 0], dtype=numpy.float64) df = threebody(1.0, 0.5, 0.5, 0.5) for i in xrange(8): ts, xs = rungekutta.rk4(df, 0, ic(0.3 * i + 20.0), 0.005, 8000) xs = xs.transpose() plot.render(xs[:, 0], xs[:, 1], 'b', xs[:, 6], xs[:, 7], 'r', xs[:, 12], xs[:, 13], 'g', xlabel='x (normalized AU)', ylabel='y (normalized AU)', title=r'3-body Orbital Interaction ($x_{14}=%.1f$)' % (0.3 * i + 20.0), legend=('Star A', 'Star B', 'Star C'), file_prefix=suffixed(file_prefix, '_3{0}'.format(chr(97 + i))))
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 pr2b(file_prefix, delay, dim): embed_run(dset='data3', delay=delay, vdim=dim, ydim=5, file_prefix=suffixed(file_prefix, '_2b'))
def pr2a(file_prefix=None): embed_run(dset='data2', delay=75, ydim=2, file_prefix=suffixed(file_prefix, '_2a'))
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)