#!/usr/bin/env python # coding: utf-8 # # Basic usage of tidynamics # # This notebook demonstrates the use of the library [tidynamics](http://lab.pdebuyl.be/tidynamics). # # tidynamics is open-source and developed for research purposes. Consider citing # the corresponding article if you use it in research or teaching material: # [![status](http://joss.theoj.org/papers/c4784e48e7514c207d95f440c2a07874/status.svg)](http://joss.theoj.org/papers/c4784e48e7514c207d95f440c2a07874) # In[ ]: get_ipython().run_line_magic('matplotlib', 'notebook') import matplotlib.pyplot as plt import numpy as np import tidynamics # ## Computing the autocorrelation function # # We generate random numbers uniformly in the range -1..1 and compute # their autocorrelation function using tidynamics's acf routine. # # *Note:* the numerical results for large lags contain fewer samples than # for short lags and are not accurate. This is intrinsic to the computation # and not a limitation of the algorithm. # In[ ]: data = -1+2*np.random.random(size=1000) plt.figure() plt.plot(data) plt.xlabel('time') plt.title('data') plt.figure() plt.plot(tidynamics.acf(data)) plt.xlabel('lag') plt.title('autocorrelation function of data') # ## Computing the mean-square displacement # # We generate a random walk using +1/-1 random steps and compute # the corresponding mean-square displacement using tidynamics' msd # routine. # # *Note:* the numerical results for large lags contain fewer samples than # for short lags and are not accurate. This is intrinsic to the computation # and not a limitation of the algorithm. # In[ ]: # Generate random numbers of +1 or -1 steps = -1 + 2*np.random.randint(0, 2, size=1000) # Add the steps to obtain the position position = np.cumsum(steps) plt.figure() plt.plot(position) plt.xlabel('time') plt.title('Position as a function of time for a random walk') plt.figure() plt.plot(tidynamics.msd(position)) plt.xlabel('lag') plt.title('Mean-square displacement for the random walk') # In[ ]: