{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Basic usage of tidynamics\n", "\n", "This notebook demonstrates the use of the library [tidynamics](http://lab.pdebuyl.be/tidynamics).\n", "\n", "tidynamics is open-source and developed for research purposes. Consider citing\n", "the corresponding article if you use it in research or teaching material:\n", "[![status](http://joss.theoj.org/papers/c4784e48e7514c207d95f440c2a07874/status.svg)](http://joss.theoj.org/papers/c4784e48e7514c207d95f440c2a07874)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%matplotlib notebook\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "import tidynamics" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Computing the autocorrelation function\n", "\n", "We generate random numbers uniformly in the range -1..1 and compute\n", "their autocorrelation function using tidynamics's acf routine.\n", "\n", "*Note:* the numerical results for large lags contain fewer samples than\n", "for short lags and are not accurate. This is intrinsic to the computation\n", "and not a limitation of the algorithm." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "data = -1+2*np.random.random(size=1000)\n", "\n", "plt.figure()\n", "plt.plot(data)\n", "plt.xlabel('time')\n", "plt.title('data')\n", "\n", "plt.figure()\n", "plt.plot(tidynamics.acf(data))\n", "plt.xlabel('lag')\n", "plt.title('autocorrelation function of data')\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Computing the mean-square displacement\n", "\n", "We generate a random walk using +1/-1 random steps and compute\n", "the corresponding mean-square displacement using tidynamics' msd\n", "routine.\n", "\n", "*Note:* the numerical results for large lags contain fewer samples than\n", "for short lags and are not accurate. This is intrinsic to the computation\n", "and not a limitation of the algorithm." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Generate random numbers of +1 or -1\n", "steps = -1 + 2*np.random.randint(0, 2, size=1000)\n", "# Add the steps to obtain the position\n", "position = np.cumsum(steps)\n", "\n", "plt.figure()\n", "plt.plot(position)\n", "plt.xlabel('time')\n", "plt.title('Position as a function of time for a random walk')\n", "\n", "plt.figure()\n", "plt.plot(tidynamics.msd(position))\n", "plt.xlabel('lag')\n", "plt.title('Mean-square displacement for the random walk')\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.4" } }, "nbformat": 4, "nbformat_minor": 2 }