Created
October 26, 2022 06:47
-
-
Save neelabalan/c48cd4a3c72b8dccb9de1a4fe199915e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Numerical Methods using Python (scipy)\n", | |
"======================================\n", | |
"\n", | |
"Overview\n", | |
"--------\n", | |
"\n", | |
"The core Python language (including the standard libraries) provide enough functionality to carry out computational research tasks. However, there are dedicated (third-party) Python libraries that provide extended functionality which\n", | |
"\n", | |
"- provide numerical tools for frequently occurring tasks\n", | |
"\n", | |
"- which are convenient to use\n", | |
"\n", | |
"- and are more efficient in terms of CPU time and memory requirements than using the code Python functionality alone.\n", | |
"\n", | |
"We list three such modules in particular:\n", | |
"\n", | |
"- The `numpy` module provides a data type specialised for “number crunching” of vectors and matrices (this is the `array` type provided by “`numpy`” as introduced in [14-numpy.ipynb](14-numpy.ipynb)), and linear algebra tools.\n", | |
"\n", | |
"- The `matplotlib` package (also knows as `pylab`) provides plotting and visualisation capabilities (see [15-visualising-data.ipynb](15-visualising-data.ipynb)) and the\n", | |
"\n", | |
"- `scipy` package (SCIentific PYthon) which provides a multitude of numerical algorithms and which is introduced in this chapter.\n", | |
"\n", | |
"Many of the numerical algorithms available through `scipy` and `numpy` are provided by established compiled libraries which are often written in Fortran or C. They will thus execute much faster than pure Python code (which is interpreted). As a rule of thumb, we expect compiled code to be two orders of magnitude faster than pure Python code.\n", | |
"\n", | |
"You can use the help function for each numerical method to find out more about the source of the implementation.\n", | |
"\n", | |
"SciPy\n", | |
"-----\n", | |
"\n", | |
"`Scipy` is built on `numpy`. All functionality from `numpy` seems to be available in `scipy` as well. For example, instead of" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"import numpy\n", | |
"x = numpy.arange(0, 10, 0.1)\n", | |
"y = numpy.sin(x)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"we can therefor also use" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": { | |
"collapsed": false, | |
"scrolled": true | |
}, | |
"outputs": [], | |
"source": [ | |
"import scipy as s\n", | |
"x = s.arange(0, 10, 0.1)\n", | |
"y = s.sin(x)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"First we need to import `scipy`:" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"import scipy" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"The `scipy` package provides information about its own structure when we use the help command:\n", | |
"\n", | |
"```python\n", | |
"help(scipy)\n", | |
"```" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"The output is very long, so we're showing just a part of it here:\n", | |
"\n", | |
" stats --- Statistical Functions [*]\n", | |
" sparse --- Sparse matrix [*]\n", | |
" lib --- Python wrappers to external libraries [*]\n", | |
" linalg --- Linear algebra routines [*]\n", | |
" signal --- Signal Processing Tools [*]\n", | |
" misc --- Various utilities that don't have another home.\n", | |
" interpolate --- Interpolation Tools [*]\n", | |
" optimize --- Optimization Tools [*]\n", | |
" cluster --- Vector Quantization / Kmeans [*]\n", | |
" fftpack --- Discrete Fourier Transform algorithms [*]\n", | |
" io --- Data input and output [*]\n", | |
" integrate --- Integration routines [*]\n", | |
" lib.lapack --- Wrappers to LAPACK library [*]\n", | |
" special --- Special Functions [*]\n", | |
" lib.blas --- Wrappers to BLAS library [*]\n", | |
" [*] - using a package requires explicit import (see pkgload)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"If we are looking for an algorithm to integrate a function, we might explore the `integrate` package:" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"```python\n", | |
"import scipy.integrate\n", | |
"\n", | |
"scipy.integrate?\n", | |
"```" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"collapsed": false | |
}, | |
"source": [ | |
"produces:\n", | |
"\n", | |
"```text\n", | |
"=============================================\n", | |
"Integration and ODEs (:mod:`scipy.integrate`)\n", | |
"=============================================\n", | |
"\n", | |
".. currentmodule:: scipy.integrate\n", | |
"\n", | |
"Integrating functions, given function object\n", | |
"============================================\n", | |
"\n", | |
".. autosummary::\n", | |
" :toctree: generated/\n", | |
"\n", | |
" quad -- General purpose integration\n", | |
" dblquad -- General purpose double integration\n", | |
" tplquad -- General purpose triple integration\n", | |
" nquad -- General purpose n-dimensional integration\n", | |
" fixed_quad -- Integrate func(x) using Gaussian quadrature of order n\n", | |
" quadrature -- Integrate with given tolerance using Gaussian quadrature\n", | |
" romberg -- Integrate func using Romberg integration\n", | |
" quad_explain -- Print information for use of quad\n", | |
" newton_cotes -- Weights and error coefficient for Newton-Cotes integration\n", | |
" IntegrationWarning -- Warning on issues during integration\n", | |
"\n", | |
"Integrating functions, given fixed samples\n", | |
"==========================================\n", | |
"\n", | |
".. autosummary::\n", | |
" :toctree: generated/\n", | |
"\n", | |
" trapz -- Use trapezoidal rule to compute integral.\n", | |
" cumtrapz -- Use trapezoidal rule to cumulatively compute integral.\n", | |
" simps -- Use Simpson's rule to compute integral from samples.\n", | |
" romb -- Use Romberg Integration to compute integral from\n", | |
" -- (2**k + 1) evenly-spaced samples.\n", | |
"\n", | |
".. seealso::\n", | |
"\n", | |
" :mod:`scipy.special` for orthogonal polynomials (special) for Gaussian\n", | |
" quadrature roots and weights for other weighting factors and regions.\n", | |
"\n", | |
"Integrators of ODE systems\n", | |
"==========================\n", | |
"\n", | |
".. autosummary::\n", | |
" :toctree: generated/\n", | |
"\n", | |
" odeint -- General integration of ordinary differential equations.\n", | |
" ode -- Integrate ODE using VODE and ZVODE routines.\n", | |
" complex_ode -- Convert a complex-valued ODE to real-valued and integrate.\n", | |
"```" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"The following sections show examples which demonstrate how to employ the algorithms provided by `scipy`.\n", | |
"\n", | |
"Numerical integration\n", | |
"---------------------\n", | |
"\n", | |
"Scientific Python provides a number of integration routines. A general purpose tool to solve integrals *I* of the kind\n", | |
"\n", | |
"$$I=\\int_a^b f(x) \\mathrm{d} x$$\n", | |
"\n", | |
"is provided by the `quad()` function of the `scipy.integrate` module.\n", | |
"\n", | |
"It takes as input arguments the function *f*(*x*) to be integrated (the “integrand”), and the lower and upper limits *a* and *b*. It returns two values (in a tuple): the first one is the computed results and the second one is an estimation of the numerical error of that result.\n", | |
"\n", | |
"Here is an example: which produces this output:" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"The numerical result is 17.864264 (+-1.55113e-11)\n" | |
] | |
} | |
], | |
"source": [ | |
"from math import cos, exp, pi\n", | |
"from scipy.integrate import quad\n", | |
"\n", | |
"# function we want to integrate\n", | |
"def f(x):\n", | |
" return exp(cos(-2 * x * pi)) + 3.2\n", | |
"\n", | |
"# call quad to integrate f from -2 to 2\n", | |
"res, err = quad(f, -2, 2)\n", | |
"\n", | |
"print(\"The numerical result is {:f} (+-{:g})\"\n", | |
" .format(res, err))" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Note that `quad()` takes optional parameters `epsabs` and `epsrel` to increase or decrease the accuracy of its computation. (Use `help(quad)` to learn more.) The default values are `epsabs=1.5e-8` and `epsrel=1.5e-8`. For the next exercise, the default values are sufficient.\n", | |
"\n", | |
"### Exercise: integrate a function\n", | |
"\n", | |
"1. Using scipy’s `quad` function, write a program that solves the following integral numerically: $I = \\int\n", | |
"_0^1\\cos(2\\pi x) dx$.\n", | |
"\n", | |
"2. Find the analytical integral and compare it with the numerical solution.\n", | |
"\n", | |
"3. Why is it important to have an estimate of the accuracy (or the error) of the numerical integral?" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### Exercise: plot before you integrate\n", | |
"\n", | |
"It is good practice to plot the integrand function to check whether it is “well behaved” before you attempt to integrate. Singularities (i.e. $x$ values where the $f(x)$ tends towards minus or plus infinity) or other irregular behaviour (such as $f(x)=\\sin(\\frac{1}{x}$) close to $x = 0$ are difficult to handle numerically.\n", | |
"\n", | |
"1. Write a function with name `plotquad` which takes the same arguments as the quad command (*i.e.* $f$, $a$ and $b$) and which \n", | |
"- (i) creates a plot of the integrand $f(x)$ and \n", | |
"- (ii) computes the integral numerically using the `quad` function. The return values should be as for the `quad` function." | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Solving ordinary differential equations\n", | |
"---------------------------------------\n", | |
"\n", | |
"To solve an ordinary differential equation of the type\n", | |
"$$\\frac{\\mathrm{d}y}{\\mathrm{d}t}(t) = f(y,t)$$\n", | |
"\n", | |
"with a given $y(t_0)=y_0$, we can use `scipy`’s `odeint` function. Here is a (self explaining) example program (`useodeint.py`) to find \n", | |
"\n", | |
"$$y(t) \\quad \\mathrm{for}\\quad t\\in[0,2]$$\n", | |
" given this differential equation:\n", | |
"$$\\frac{\\mathrm{d}y}{\\mathrm{d}t}(t) = -2yt \\quad \\mathrm{with} \\quad y(0)=1.$$" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"<matplotlib.text.Text at 0x10cad9320>" | |
] | |
}, | |
"execution_count": 5, | |
"metadata": {}, | |
"output_type": "execute_result" | |
}, | |
{ | |
"data": { | |
"image/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m/z37AvNBZ0+EG9AE6A+tKeF2/zeR9\nl/pdlu/7bA50jt2vC2xKxn87U60FoYV1yVWW7xNAEwDKwDn3PPBZKZfot1lGZfguQb/LMnPO/Z+L\nbVHknPsK2MCB68nK/ftMtQKhhXXJVZbvE6BnrMm5wMw6VE60jKTfZnLpd1kBZvYTfOvspWIvlfv3\nGfU0V0l9rwKtnXNfx/bFmgscFTiTiH6XFWBmdYHHgF/HWhIJSbUWxA6gdZHHrWLPFb/miINcI95B\nv0/n3FfOua9j958GqptZip2qmzb020wS/S7Lz8yq4YvDP51zT8S5pNy/z1QrEN8vrDOzGviFdfOK\nXTMPOBe+X6kdd2GdAGX4Pov2QZpZN/zU508rN2ZaMUruG9dvs3xK/C71u6yQ+4G3nHN3lvB6uX+f\nKdXF5LSwLqnK8n0CZ5jZpcAe4BtgVLjEqc3MZgI5QCMz2wZMAmqg32a5Hey7RL/LcjGz3sA5wBtm\n9hrggN/jZzBW+PephXIiIhJXqnUxiYhIilCBEBGRuFQgREQkLhUIERGJSwVCRETiUoEQEZG4VCBE\nEmBmDWLz9UUyjgqESGIOBX4VOoRIFFQgRBJzM9A2dqjNraHDiCSTVlKLJMDM2gDznXOdQmcRSTa1\nIEREJC4VCBERiUsFQiQxXwL1QocQiYIKhEgCYmcUrDSzdRqklkyjQWoREYlLLQgREYlLBUJEROJS\ngRARkbhUIEREJC4VCBERiUsFQkRE4lKBEBGRuFQgREQkrv8Htv2R2Ngj0ZQAAAAASUVORK5CYII=\n", | |
"text/plain": [ | |
"<matplotlib.figure.Figure at 0x10bc09160>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"%matplotlib inline\n", | |
"from scipy.integrate import odeint\n", | |
"import numpy as N\n", | |
"\n", | |
"def f(y, t):\n", | |
" \"\"\"this is the rhs of the ODE to integrate, i.e. dy/dt=f(y,t)\"\"\"\n", | |
" return -2 * y * t\n", | |
"\n", | |
"y0 = 1 # initial value\n", | |
"a = 0 # integration limits for t\n", | |
"b = 2\n", | |
"\n", | |
"t = N.arange(a, b, 0.01) # values of t for\n", | |
" # which we require\n", | |
" # the solution y(t)\n", | |
"y = odeint(f, y0, t) # actual computation of y(t)\n", | |
"\n", | |
"import pylab # plotting of results\n", | |
"pylab.plot(t, y)\n", | |
"pylab.xlabel('t'); pylab.ylabel('y(t)')" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"The `odeint` command takes a number of optional parameters to change the default error tolerance of the integration (and to trigger the production of extra debugging output). Use the help command to explore these:\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"collapsed": true | |
}, | |
"source": [ | |
"```python\n", | |
"help(scipy.integrate.odeint)\n", | |
"```\n", | |
"\n", | |
"will show:\n", | |
"\n", | |
"```\n", | |
"Help on function odeint in module scipy.integrate.odepack:\n", | |
"\n", | |
"odeint(func, y0, t, args=(), Dfun=None, col_deriv=0, full_output=0, ml=None, mu=None, rtol=None, atol=None, tcrit=None, h0=0.0, hmax=0.0, hmin=0.0, ixpr=0, mxstep=0, mxhnil=0, mxordn=12, mxords=5, printmessg=0)\n", | |
" Integrate a system of ordinary differential equations.\n", | |
" \n", | |
" Solve a system of ordinary differential equations using lsoda from the\n", | |
" FORTRAN library odepack.\n", | |
" \n", | |
" Solves the initial value problem for stiff or non-stiff systems\n", | |
" of first order ode-s::\n", | |
" \n", | |
" dy/dt = func(y, t0, ...)\n", | |
" \n", | |
" where y can be a vector.\n", | |
" \n", | |
" *Note*: The first two arguments of ``func(y, t0, ...)`` are in the\n", | |
" opposite order of the arguments in the system definition function used\n", | |
" by the `scipy.integrate.ode` class.\n", | |
" \n", | |
" Parameters\n", | |
" ----------\n", | |
" func : callable(y, t0, ...)\n", | |
" Computes the derivative of y at t0.\n", | |
" y0 : array\n", | |
" Initial condition on y (can be a vector).\n", | |
" t : array\n", | |
" A sequence of time points for which to solve for y. The initial\n", | |
" value point should be the first element of this sequence.\n", | |
" args : tuple, optional\n", | |
" Extra arguments to pass to function.\n", | |
" Dfun : callable(y, t0, ...)\n", | |
" Gradient (Jacobian) of `func`.\n", | |
" col_deriv : bool, optional\n", | |
" True if `Dfun` defines derivatives down columns (faster),\n", | |
" otherwise `Dfun` should define derivatives across rows.\n", | |
" full_output : bool, optional\n", | |
" True if to return a dictionary of optional outputs as the second output\n", | |
" printmessg : bool, optional\n", | |
" Whether to print the convergence message\n", | |
" \n", | |
" Returns\n", | |
" -------\n", | |
" y : array, shape (len(t), len(y0))\n", | |
" Array containing the value of y for each desired time in t,\n", | |
" with the initial value `y0` in the first row.\n", | |
" infodict : dict, only returned if full_output == True\n", | |
" Dictionary containing additional output information\n", | |
" \n", | |
" ======= ============================================================\n", | |
" key meaning\n", | |
" ======= ============================================================\n", | |
" 'hu' vector of step sizes successfully used for each time step.\n", | |
" 'tcur' vector with the value of t reached for each time step.\n", | |
" (will always be at least as large as the input times).\n", | |
" 'tolsf' vector of tolerance scale factors, greater than 1.0,\n", | |
" computed when a request for too much accuracy was detected.\n", | |
" 'tsw' value of t at the time of the last method switch\n", | |
" (given for each time step)\n", | |
" 'nst' cumulative number of time steps\n", | |
" 'nfe' cumulative number of function evaluations for each time step\n", | |
" 'nje' cumulative number of jacobian evaluations for each time step\n", | |
" 'nqu' a vector of method orders for each successful step.\n", | |
" 'imxer' index of the component of largest magnitude in the\n", | |
" weighted local error vector (e / ewt) on an error return, -1\n", | |
" otherwise.\n", | |
" 'lenrw' the length of the double work array required.\n", | |
" 'leniw' the length of integer work array required.\n", | |
" 'mused' a vector of method indicators for each successful time step:\n", | |
" 1: adams (nonstiff), 2: bdf (stiff)\n", | |
" ======= ============================================================\n", | |
" \n", | |
" Other Parameters\n", | |
" ----------------\n", | |
" ml, mu : int, optional\n", | |
" If either of these are not None or non-negative, then the\n", | |
" Jacobian is assumed to be banded. These give the number of\n", | |
" lower and upper non-zero diagonals in this banded matrix.\n", | |
" For the banded case, `Dfun` should return a matrix whose\n", | |
" rows contain the non-zero bands (starting with the lowest diagonal).\n", | |
" Thus, the return matrix `jac` from `Dfun` should have shape\n", | |
" ``(ml + mu + 1, len(y0))`` when ``ml >=0`` or ``mu >=0``.\n", | |
" The data in `jac` must be stored such that ``jac[i - j + mu, j]``\n", | |
" holds the derivative of the `i`th equation with respect to the `j`th\n", | |
" state variable. If `col_deriv` is True, the transpose of this\n", | |
" `jac` must be returned.\n", | |
" rtol, atol : float, optional\n", | |
" The input parameters `rtol` and `atol` determine the error\n", | |
" control performed by the solver. The solver will control the\n", | |
" vector, e, of estimated local errors in y, according to an\n", | |
" inequality of the form ``max-norm of (e / ewt) <= 1``,\n", | |
" where ewt is a vector of positive error weights computed as\n", | |
" ``ewt = rtol * abs(y) + atol``.\n", | |
" rtol and atol can be either vectors the same length as y or scalars.\n", | |
" Defaults to 1.49012e-8.\n", | |
" tcrit : ndarray, optional\n", | |
" Vector of critical points (e.g. singularities) where integration\n", | |
" care should be taken.\n", | |
" h0 : float, (0: solver-determined), optional\n", | |
" The step size to be attempted on the first step.\n", | |
" hmax : float, (0: solver-determined), optional\n", | |
" The maximum absolute step size allowed.\n", | |
" hmin : float, (0: solver-determined), optional\n", | |
" The minimum absolute step size allowed.\n", | |
" ixpr : bool, optional\n", | |
" Whether to generate extra printing at method switches.\n", | |
" mxstep : int, (0: solver-determined), optional\n", | |
" Maximum number of (internally defined) steps allowed for each\n", | |
" integration point in t.\n", | |
" mxhnil : int, (0: solver-determined), optional\n", | |
" Maximum number of messages printed.\n", | |
" mxordn : int, (0: solver-determined), optional\n", | |
" Maximum order to be allowed for the non-stiff (Adams) method.\n", | |
" mxords : int, (0: solver-determined), optional\n", | |
" Maximum order to be allowed for the stiff (BDF) method.\n", | |
" \n", | |
" See Also\n", | |
" --------\n", | |
" ode : a more object-oriented integrator based on VODE.\n", | |
" quad : for finding the area under a curve.\n", | |
" \n", | |
" Examples\n", | |
" --------\n", | |
" The second order differential equation for the angle `theta` of a\n", | |
" pendulum acted on by gravity with friction can be written::\n", | |
" \n", | |
" theta''(t) + b*theta'(t) + c*sin(theta(t)) = 0\n", | |
" \n", | |
" where `b` and `c` are positive constants, and a prime (') denotes a\n", | |
" derivative. To solve this equation with `odeint`, we must first convert\n", | |
" it to a system of first order equations. By defining the angular\n", | |
" velocity ``omega(t) = theta'(t)``, we obtain the system::\n", | |
" \n", | |
" theta'(t) = omega(t)\n", | |
" omega'(t) = -b*omega(t) - c*sin(theta(t))\n", | |
" \n", | |
" Let `y` be the vector [`theta`, `omega`]. We implement this system\n", | |
" in python as:\n", | |
" \n", | |
" >>> def pend(y, t, b, c):\n", | |
" ... theta, omega = y\n", | |
" ... dydt = [omega, -b*omega - c*np.sin(theta)]\n", | |
" ... return dydt\n", | |
" ...\n", | |
" \n", | |
" We assume the constants are `b` = 0.25 and `c` = 5.0:\n", | |
" \n", | |
" >>> b = 0.25\n", | |
" >>> c = 5.0\n", | |
" \n", | |
" For initial conditions, we assume the pendulum is nearly vertical\n", | |
" with `theta(0)` = `pi` - 0.1, and it initially at rest, so\n", | |
" `omega(0)` = 0. Then the vector of initial conditions is\n", | |
" \n", | |
" >>> y0 = [np.pi - 0.1, 0.0]\n", | |
" \n", | |
" We generate a solution 101 evenly spaced samples in the interval\n", | |
" 0 <= `t` <= 10. So our array of times is:\n", | |
" \n", | |
" >>> t = np.linspace(0, 10, 101)\n", | |
" \n", | |
" Call `odeint` to generate the solution. To pass the parameters\n", | |
" `b` and `c` to `pend`, we give them to `odeint` using the `args`\n", | |
" argument.\n", | |
" \n", | |
" >>> from scipy.integrate import odeint\n", | |
" >>> sol = odeint(pend, y0, t, args=(b, c))\n", | |
" \n", | |
" The solution is an array with shape (101, 2). The first column\n", | |
" is `theta(t)`, and the second is `omega(t)`. The following code\n", | |
" plots both components.\n", | |
" \n", | |
" >>> import matplotlib.pyplot as plt\n", | |
" >>> plt.plot(t, sol[:, 0], 'b', label='theta(t)')\n", | |
" >>> plt.plot(t, sol[:, 1], 'g', label='omega(t)')\n", | |
" >>> plt.legend(loc='best')\n", | |
" >>> plt.xlabel('t')\n", | |
" >>> plt.grid()\n", | |
" >>> plt.show()\n", | |
"\n", | |
"```" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### Exercise: using `odeint`\n", | |
"\n", | |
"1. Open a new file with name `testodeint.py` file in a text editor.\n", | |
"\n", | |
"2. Write a program that computes the solution *y*(*t*) of this ODE using the `odeint` algorithm:\n", | |
" $$\\frac{\\mathrm{d}y}{\\mathrm{d}t} = -\\exp(-t)(10\\sin(10t)+\\cos(10t))$$\n", | |
" from $t=0$ to $t = 10$. The initial value is $y(0)=1$.\n", | |
"\n", | |
"3. You should display the solution graphically at points $t=0$, $t=0.01$, $t=0.02$, ..., $t=9.99$, $t=10$.\n", | |
"\n", | |
"Hint: a part of the solution $y(t)$ is shown in the figure below.\n", | |
"\n", | |
"<img src=\"scipy/code/odeintsolution8to10.png\" alt=\"image\" style=\"width:100.0%\" />" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Root finding\n", | |
"------------\n", | |
"\n", | |
"If you try to find a $x$ such that\n", | |
"$$f(x)=0$$\n", | |
"then this is called *root finding*. Note that problems like $g(x)=h(x)$ fall in this category as you can rewrite them as $f(x)=g(x)−h(x)=0$.\n", | |
"\n", | |
"A number of root finding tools are available in `scipy`’s `optimize` module.\n", | |
"\n", | |
"### Root finding using the bisection method\n", | |
"\n", | |
"First we introduce the `bisect` algorithm which is (i) robust and (ii) slow but conceptually very simple.\n", | |
"\n", | |
"Suppose we need to compute the roots of *f*(*x*)=*x*<sup>3</sup> − 2*x*<sup>2</sup>. This function has a (double) root at *x* = 0 (this is trivial to see) and another root which is located between *x* = 1.5 (where *f*(1.5)= − 1.125) and *x* = 3 (where *f*(3)=9). It is pretty straightforward to see that this other root is located at *x* = 2. Here is a program that determines this root numerically:" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"The root x is approximately x= 2.00000023842,\n", | |
"the error is less than 1e-6.\n", | |
"The exact error is -2.38419e-07.\n" | |
] | |
} | |
], | |
"source": [ | |
"from scipy.optimize import bisect\n", | |
"\n", | |
"def f(x):\n", | |
" \"\"\"returns f(x)=x^3-2x^2. Has roots at\n", | |
" x=0 (double root) and x=2\"\"\"\n", | |
" return x ** 3 - 2 * x ** 2\n", | |
"\n", | |
"# main program starts here\n", | |
"x = bisect(f, 1.5, 3, xtol=1e-6)\n", | |
"\n", | |
"print(\"The root x is approximately x=%14.12g,\\n\"\n", | |
" \"the error is less than 1e-6.\" % (x))\n", | |
"print(\"The exact error is %g.\" % (2 - x))" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"The `bisect()` method takes three compulsory arguments: (i) the function *f*(*x*), (ii) a lower limit *a* (for which we have chosen 1.5 in our example) and (ii) an upper limit *b* (for which we have chosen 3). The optional parameter `xtol` determines the maximum error of the method.\n", | |
"\n", | |
"One of the requirements of the bisection method is that the interval \\[*a*, *b*\\] has to be chosen such that the function is either positive at *a* and negative at *b*, or that the function is negative at *a* and postive at *b*. In other words: *a* and *b* have to enclose a root.\n", | |
"\n", | |
"### Exercise: root finding using the bisect method\n", | |
"\n", | |
"1. Write a program with name `sqrttwo.py` to determine an approximation of $\\sqrt{2}$ by finding a root *x* of the function $f(x)=2 − x^2$ using the bisection algorithm. Choose a tolerance for the approximation of the root of 10<sup>−8</sup>.\n", | |
"\n", | |
"2. Document your choice of the initial bracket $[a, b]$ for the root: which values have you chosen for *a* and for *b* and why?\n", | |
"\n", | |
"3. Study the results:\n", | |
"\n", | |
" - Which value for the root *x* does the bisection algorithm return?\n", | |
"\n", | |
" - Compute the value of $\\\\sqrt{2}$ using `math.sqrt(2)` and compare this with the approximation of the root. How big is the absolute error of *x*? How does this compare with `xtol`?" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### Root finding using the `fsolve` funcion\n", | |
"\n", | |
"A (often) better (in the sense of “more efficient”) algorithm than the bisection algorithm is implemented in the general purpose `fsolve()` function for root finding of (multidimensional) functions. This algorithm needs only one starting point close to the suspected location of the root (but is not garanteed to converge).\n", | |
"\n", | |
"Here is an example:" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"The root x is approximately x= 2.000000000000006661\n", | |
"The exact error is -6.66134e-15.\n" | |
] | |
} | |
], | |
"source": [ | |
"from scipy.optimize import fsolve\n", | |
"\n", | |
"def f(x):\n", | |
" return x ** 3 - 2 * x ** 2\n", | |
"\n", | |
"x = fsolve(f, 3) # one root is at x=2.0\n", | |
"\n", | |
"print(\"The root x is approximately x=%21.19g\" % x)\n", | |
"print(\"The exact error is %g.\" % (2 - x))" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"The return value[6] of `fsolve` is a numpy array of length *n* for a root finding problem with *n* variables. In the example above, we have *n* = 1.\n", | |
"\n", | |
"Interpolation\n", | |
"-------------\n", | |
"\n", | |
"Given a set of *N* points $(x_i, y_i)$ with $i = 1, 2, …N$, we sometimes need a function $\\hat{f}(x)$ which returns $y_i = f(x_i)$ where $x == x_i$, and which in addition provides some interpolation of the data $(x_i, y_i)$ for all $x$.\n", | |
"\n", | |
"The function `y0 = scipy.interpolate.interp1d(x,y,kind=’nearest’)` does this interpolation based on splines of varying order. Note that the function `interp1d` returns *a function* `y0` which will then interpolate the x-y data for any given $x$ when called as $y0(x)$.\n", | |
"\n", | |
"The code below demonstrates this, and shows the different interpolation kinds." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"<matplotlib.text.Text at 0x110221358>" | |
] | |
}, | |
"execution_count": 8, | |
"metadata": {}, | |
"output_type": "execute_result" | |
}, | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXkAAAEPCAYAAACneLThAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XlcVNX7wPHPGTZZBRQVUBF3TVFcSNuEyvJrm21muaSW\ntpqZbVaGS5aV32+/suXbZmbZvmrfMi2j1DTNJTSXXAHFHVD2Zeb5/TGIqIDIAMPyvF+veTkz995z\nnxn14XLuOc8xIoJSSqm6yeLsAJRSSlUdTfJKKVWHaZJXSqk6TJO8UkrVYZrklVKqDtMkr5RSdZhr\nVZ/AGLMHOAbYgHwRiarqcyqllLKr8iSPPblHi0hqNZxLKaVUMdXRXWOq6TxKKaVOUx3JV4Alxpg1\nxpgx1XA+pZRShaqju+ZCEdlvjAnCnuy3iMjyajivUkrVe1We5EVkf+Gfh40xXwNRQFGSN8Zo8Ryl\nlKoAETFn26dKu2uMMV7GGJ/C597AFcCm0/cTEX2IEBsb6/QYaspDvwv9LvS7KPtRXlV9Jd8U+Lrw\nat0VmC8ii6v4nEoppQpVaZIXkd1A96o8h1JKqdLp0MYaJDo62tkh1Bj6XZyk38VJ+l2cO3MufTtV\nEoAx4uwYlFKqtjHGIOW48VodQyiVUjVUq1atSEhIcHYYqgxhYWHs2bOnwsfrlbxS9Vjh1aCzw1Bl\nKO3vqLxX8tonr5RSdZgmeaWUqsM0ySulVB2mSV4pVSuMGjWKp59+2tlhnNXAgQP54IMPnB1GEU3y\nSqk6JyYmhjlz5jjl3N9//z3Dhw8v177VEacOoVRKnWH37gQmT57Lvn02QkMtTJ8+kvDwsGpvQ1WC\nGlBkR5RSzlHS/79du/ZImzYTB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uSVUqoO0ySvlFJ1\nmCZ5pZSqwzTJK6VUHaZJXiml6jBN8kopVYdpkldKqTpMk7xSpzHG9CpckMHdGONtjNlUHwuDqbpB\nZ7wqVQJjzDTAs/CRJCLPOzkkpSpEk7xSJTDGuGEvopcNXKAL0avaSrtrlCpZY8AH8AUaODkWpSpM\nr+SVKoEx5lvstcvDgRARGefkkJSqEFdnB6BUTWOMGQ7kicgnhQvOrzDGRItInJNDU+qc6ZW8UkrV\nYdonr5RSdZgmeaWUqsM0ySulVB2mSV4ppeowTfJKKVWHaZJXSqk6TJO8UkrVYZrklVKqDvt/J4VT\nRzYk92MAAAAASUVORK5CYII=\n", | |
"text/plain": [ | |
"<matplotlib.figure.Figure at 0x10fe4eb70>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"import numpy as np\n", | |
"import scipy.interpolate\n", | |
"import pylab\n", | |
"\n", | |
"def create_data(n):\n", | |
" \"\"\"Given an integer n, returns n data points\n", | |
" x and values y as a numpy.array.\"\"\"\n", | |
" xmax = 5.\n", | |
" x = np.linspace(0, xmax, n)\n", | |
" y = - x**2\n", | |
" #make x-data somewhat irregular\n", | |
" y += 1.5 * np.random.normal(size=len(x))\n", | |
" return x, y\n", | |
"\n", | |
"#main program\n", | |
"n = 10\n", | |
"x, y = create_data(n)\n", | |
"\n", | |
"#use finer and regular mesh for plot\n", | |
"xfine = np.linspace(0.1, 4.9, n * 100)\n", | |
"#interpolate with piecewise constant function (p=0)\n", | |
"y0 = scipy.interpolate.interp1d(x, y, kind='nearest')\n", | |
"#interpolate with piecewise linear func (p=1)\n", | |
"y1 = scipy.interpolate.interp1d(x, y, kind='linear')\n", | |
"#interpolate with piecewise constant func (p=2)\n", | |
"y2 = scipy.interpolate.interp1d(x, y, kind='quadratic')\n", | |
"\n", | |
"pylab.plot(x, y, 'o', label='data point')\n", | |
"pylab.plot(xfine, y0(xfine), label='nearest')\n", | |
"pylab.plot(xfine, y1(xfine), label='linear')\n", | |
"pylab.plot(xfine, y2(xfine), label='cubic')\n", | |
"pylab.legend()\n", | |
"pylab.xlabel('x')" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Curve fitting\n", | |
"-------------\n", | |
"\n", | |
"We have already seen in [the numpy chapter](14-numpy.ipynb) that we can fit polynomial functions through a data set using the `numpy.polyfit` function. Here, we introduce a more generic curve fitting algorithm.\n", | |
"\n", | |
"Scipy provides a somewhat generic function (based on the Levenburg-Marquardt algorithm )through `scipy.optimize.curve_fit` to fit a given (Python) function to a given data set. The assumption is that we have been given a set of data with points $x_1, x_2, …x_N$ and with corresponding function values $y_i$ and a dependence of $y_i$ on $x_i$ such that $y_i=f(x_i,\\vec{p})$. We want to determine the parameter vector $\\vec{p}=(p_1, p_2, \\ldots,\n", | |
"p_k)$ so that $r$, the sum of the residuals, is as small as possible:\n", | |
"\n", | |
"$$r = \\sum\\limits_{i=1}^N \\left(y_i - f(x_i, \\vec{p})\\right)^2$$\n", | |
"\n", | |
"Curve fitting is of particular use if the data is noisy: for a given $x_i$ and $y_i=f(x_i,\\vec{p})$ we have a (unknown) error term $\\epsilon_i$ so that $y_i=f(x_i,\\vec{p})+\\epsilon_i$.\n", | |
"\n", | |
"We use the following example to clarify this:\n", | |
"$$f(x,\\vec{p}) = a \\exp(-b x) + c, \\quad\\mathrm{i.e.}\\quad \\vec{p}=\\mathtt{a,b,c}$$" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Optimal parameters are a=2.524, b=1.04295, and c=0.378715\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"<matplotlib.legend.Legend at 0x11056dac8>" | |
] | |
}, | |
"execution_count": 9, | |
"metadata": {}, | |
"output_type": "execute_result" | |
}, | |
{ | |
"data": { | |
"image/png": "iVBORw0KG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U+7uOPP87TTz/tUUxTp06lW7dutGtXfGVHfrmmpaWRlpZW8P6ECRN8O3eNMWY6\ncNBa+6iLz2Ostfucz7sCs621zYvZzu2G18LGLR3HjqM7mHb7tDLvKyLeFwpJvl+/fgwcOJB77733\ngs/KmuRfeOEFDhw4QExMDBERETz00EMexXTq1Cn++Mc/8tprrxX7eUAaXo0xVwFJwLXGmLXGmDXG\nmBuMMcONMcOcmw0wxvxkjFkLvADc5UkwrozpMYb5W+azYf8Gbx5WRMJUnz59WLp0KSNHjqROnTps\n2bKFFi1akJqayuDBg9mxYwe33norderUYdKkSSUeKysri1mzZtG/f3+OHTtGYmKix3FVq1aN06dP\nk51dtMbbh6y1fns4TueZZ//1rL39g9s93l9EvKc8f8v+kpCQYKdMmVLwunnz5nbJkiUFz1NTU906\nzsKFC+2IESOstdb279/f5uXllSuul156yX711VfFfuaqXJ3ve5R3AzqtQVmM/M1IXlzxIit2raBb\n026BDkdESmEmlL9XtU3xXZWQdaO6acWKFbzwwgs0adKETz75hBMnTlywutO8efOoVKkSy5Yto0OH\nDixYsIAnn3ySNm3aFHvM2NhYtmzZwnXXXeeV36M0IZPka1Spwbhe4xi7ZCxLBi8JyDJaIuI+XyZo\nf+nWrRs1atRg9OjRtGvXjldfffW8z3fs2EG7du1o2bIl48aN409/+hN169alWTPHAM7ly5cD0KNH\nj4J96taty+bNm/32O4TUvL1DOw0l81gmi9MXBzoUEQlhZblJ3LhxI23btgWgcuXz74ubNWtGy5Yt\n2b9/P3Xq1KFu3brcfPPN1KhRA3Ak98IJHuDEiRNERhZdK8N3QirJV46ozMTEiTyR+kTQt+yLSPCK\niYkhPT291O32799Pw4YNCy4KMTExHD9+bp2LTZs28cMPPzB//nx69eoFwOeffw7AqlWrGDt27AW5\n6tChQzRq1Mhbv0qpQirJAwxoN4CzeWd5/es3GDRoAomJKQwaNIGMjO2BDk1EgkjRu/XCr8eOHcvE\niROpX78+zz//vMtjrFixgp49exa87t2793kDoRYuXMgXX3yBtZaTJ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IhLGlORFRMKYkryISBhTkhcRCWNK8iIiYUxJXio0Y0wXY8wPxpiq\nxphIY8xPwTrJlognNOJVKjxjzP8BNZyPndbapwMckojXKMlLhWeMqYJjwroTQE+rPwoJI6quEYEG\nOJbZqw1UD3AsIl6lO3mp8Iwxn+KYw7sFEGutHRXgkES8xutTDYuEEmPMfwOnrbUfOKei/ZcxJsFa\nmxbg0ES8QnfyIiJhTHXyIiJhTEleRCSMKcmLiIQxJXkRkTCmJC8iEsaU5EVEwpiSvIhIGFOSFxEJ\nY/8Pi+zxhMGjLI0AAAAASUVORK5CYII=\n", | |
"text/plain": [ | |
"<matplotlib.figure.Figure at 0x10fe4e4e0>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"import numpy as np\n", | |
"from scipy.optimize import curve_fit\n", | |
"\n", | |
"\n", | |
"def f(x, a, b, c):\n", | |
" \"\"\"Fit function y=f(x,p) with parameters p=(a,b,c). \"\"\"\n", | |
" return a * np.exp(- b * x) + c\n", | |
"\n", | |
"#create fake data\n", | |
"x = np.linspace(0, 4, 50)\n", | |
"y = f(x, a=2.5, b=1.3, c=0.5)\n", | |
"#add noise\n", | |
"yi = y + 0.2 * np.random.normal(size=len(x))\n", | |
"\n", | |
"#call curve fit function\n", | |
"popt, pcov = curve_fit(f, x, yi)\n", | |
"a, b, c = popt\n", | |
"print(\"Optimal parameters are a=%g, b=%g, and c=%g\" % (a, b, c))\n", | |
"\n", | |
"#plotting\n", | |
"import pylab\n", | |
"yfitted = f(x, *popt) # equivalent to f(x, popt[0], popt[1], popt[2])\n", | |
"pylab.plot(x, yi, 'o', label='data $y_i$')\n", | |
"pylab.plot(x, yfitted, '-', label='fit $f(x_i)$')\n", | |
"pylab.xlabel('x')\n", | |
"pylab.legend()" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Note that in the source code above we define the fitting function $y = f(x)$ through Python code. We can thus fit (nearly) arbitrary functions using the `curve_fit` method.\n", | |
"\n", | |
"The `curve_fit` function returns a tuple `popt, pcov`. The first entry `popt` contains a tuple of the OPTimal Parameters (in the sense that these minimise equation (\\[eq:1\\]). The second entry contains the covariance matrix for all parameters. The diagonals provide the variance of the parameter estimations.\n", | |
"\n", | |
"For the curve fitting process to work, the Levenburg-Marquardt algorithm needs to start the fitting process with initial guesses for the final parameters. If these are not specified (as in the example above), the value “1.0“ is used for the initial guess.\n", | |
"\n", | |
"If the algorithm fails to fit a function to data (even though the function describes the data reasonably), we need to give the algorithm better estimates for the initial parameters. For the example shown above, we could give the estimates to the `curve_fit` function by changing the line\n", | |
"\n", | |
"```python\n", | |
"popt, pcov = curve_fit(f, x, yi)\n", | |
"```\n", | |
"\n", | |
"to\n", | |
"\n", | |
"```python\n", | |
"popt, pcov = curve_fit(f, x, yi, p0=(2,1,0.6))\n", | |
"```" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"if our initial guesses would be *a* = 2, *b* = 1 and *c* = 0.6. Once we take the algorithm “roughly in the right area” in parameter space, the fitting usually works well.\n", | |
"\n", | |
"Fourier transforms\n", | |
"------------------\n", | |
"\n", | |
"In the next example, we create a signal as a superposition of a 50 Hz and 70 Hz sine wave (with a slight phase shift between them). We then Fourier transform the signal and plot the absolute value of the (complex) discrete Fourier transform coefficients against frequency, and expect to see peaks at 50Hz and 70Hz." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 10, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"<matplotlib.text.Text at 0x1108284e0>" | |
] | |
}, | |
"execution_count": 10, | |
"metadata": {}, | |
"output_type": "execute_result" | |
}, | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAZIAAAEPCAYAAABoekJnAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJztnXmYHVWZ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ElFTkSuQmCC\n", | |
"text/plain": [ | |
"<matplotlib.figure.Figure at 0x110678320>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"import scipy\n", | |
"import matplotlib.pyplot as plt\n", | |
"pi = scipy.pi\n", | |
"\n", | |
"signal_length = 0.5 #[seconds]\n", | |
"sample_rate=500 #sampling rate [Hz]\n", | |
"dt = 1./sample_rate #time between two samples [s]\n", | |
"\n", | |
"df = 1/signal_length #frequency between points in\n", | |
" #in frequency domain [Hz] \n", | |
"t=scipy.arange(0,signal_length,dt) #the time vector\n", | |
"n_t=len(t) #length of time vector\n", | |
"\n", | |
"#create signal\n", | |
"y=scipy.sin(2*pi*50*t)+scipy.sin(2*pi*70*t+pi/4)\n", | |
"\n", | |
"#compute fourier transform\n", | |
"f=scipy.fft(y)\n", | |
"\n", | |
"#work out meaningful frequencies in fourier transform\n", | |
"freqs=df*scipy.arange(0,(n_t-1)/2.,dtype='d') #d=double precision float\n", | |
"n_freq=len(freqs)\n", | |
"\n", | |
"#plot input data y against time\n", | |
"plt.subplot(2,1,1)\n", | |
"plt.plot(t,y,label='input data')\n", | |
"plt.xlabel('time [s]')\n", | |
"plt.ylabel('signal')\n", | |
"\n", | |
"#plot frequency spectrum \n", | |
"plt.subplot(2,1,2)\n", | |
"plt.plot(freqs,abs(f[0:n_freq]),\n", | |
" label='abs(fourier transform)')\n", | |
"plt.xlabel('frequency [Hz]')\n", | |
"plt.ylabel('abs(DFT(signal))')" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"The lower plot shows the discrete Fourier transform computed from the data shown in the upper plot." | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Optimisation\n", | |
"------------\n", | |
"\n", | |
"Often we need to find the maximum or minimum of a particular function *f*(*x*) where *f* is a scalar function but *x* could be a vector. Typical applications are the minimisation of entities such as cost, risk and error, or the maximisation of productivity, efficiency and profit. Optimisation routines typically provide a method to minimise a given function: if we need to maximise *f*(*x*) we create a new function *g*(*x*) that reverses the sign of *f*, i.e. *g*(*x*)= − *f*(*x*) and we minimise *g*(*x*).\n", | |
"\n", | |
"Below, we provide an example showing (i) the definition of the test function and (ii) the call of the `scipy.optimize.fmin` function which takes as argument a function *f* to minimise and an initial value *x*<sub>0</sub> from which to start the search for the minimum, and which returns the value of *x* for which *f*(*x*) is (locally) minimised. Typically, the search for the minimum is a local search, i.e. the algorithm follows the local gradient. We repeat the search for the minimum for two values (*x*<sub>0</sub> = 1.0 and *x*<sub>0</sub> = 2.0, respectively) to demonstrate that depending on the starting value we may find different minimar of the function *f*.\n", | |
"\n", | |
"The majority of the commands (after the two calls to `fmin`) in the file `fmin1.py` creates the plot of the function, the start points for the searches and the minima obtained:" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 11, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Optimization terminated successfully.\n", | |
" Current function value: -2.023866\n", | |
" Iterations: 16\n", | |
" Function evaluations: 32\n", | |
"Start search at x=1., minimum is [ 0.23964844]\n", | |
"Optimization terminated successfully.\n", | |
" Current function value: -1.000529\n", | |
" Iterations: 16\n", | |
" Function evaluations: 32\n", | |
"Start search at x=2., minimum is [ 3.13847656]\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"<matplotlib.legend.Legend at 0x11092c588>" | |
] | |
}, | |
"execution_count": 11, | |
"metadata": {}, | |
"output_type": "execute_result" | |
}, | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXkAAAEPCAYAAACneLThAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xl8TNf7B/DPCaKJJGhCEJGkoXRRqX4ttSZVe9Ha1VKq\nqguKFi3VSH2/LX76pYqW1k7Vt6pqi9aS2IuUUCW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coI2XwCP\naBwLY0XCZ/KMWSGE+AXAcgBhAKoQ0VCNQ2LMZm69aAhj1ggh+gIwENEP2Yt67xJCRBJRvMahMWYT\nPpNnjDEXxjV5xhhzYZzkGWPMhXGSZ4wxF8ZJnjHGXBgnecYYc2Gc5BljzIVxkmeMMRfGSZ4xxlzY\n/wMt18pkrenrOQAAAABJRU5ErkJggg==\n", | |
"text/plain": [ | |
"<matplotlib.figure.Figure at 0x1104729e8>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"from scipy import arange, cos, exp\n", | |
"from scipy.optimize import fmin\n", | |
"import pylab\n", | |
"\n", | |
"def f(x):\n", | |
" return cos(x) - 3 * exp( -(x - 0.2) ** 2)\n", | |
"\n", | |
"# find minima of f(x),\n", | |
"# starting from 1.0 and 2.0 respectively\n", | |
"minimum1 = fmin(f, 1.0)\n", | |
"print(\"Start search at x=1., minimum is\", minimum1)\n", | |
"minimum2 = fmin(f, 2.0)\n", | |
"print(\"Start search at x=2., minimum is\", minimum2)\n", | |
"\n", | |
"# plot function\n", | |
"x = arange(-10, 10, 0.1)\n", | |
"y = f(x)\n", | |
"pylab.plot(x, y, label='$\\cos(x)-3e^{-(x-0.2)^2}$')\n", | |
"pylab.xlabel('x')\n", | |
"pylab.grid()\n", | |
"pylab.axis([-5, 5, -2.2, 0.5])\n", | |
"\n", | |
"# add minimum1 to plot\n", | |
"pylab.plot(minimum1, f(minimum1), 'vr',\n", | |
" label='minimum 1')\n", | |
"# add start1 to plot\n", | |
"pylab.plot(1.0, f(1.0), 'or', label='start 1')\n", | |
"\n", | |
"# add minimum2 to plot\n", | |
"pylab.plot(minimum2,f(minimum2),'vg',\\\n", | |
" label='minimum 2')\n", | |
"# add start2 to plot\n", | |
"pylab.plot(2.0,f(2.0),'og',label='start 2')\n", | |
"\n", | |
"pylab.legend(loc='lower left')" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Calling the `fmin` function will produce some diagnostic output, which you can also see above.\n", | |
"\n", | |
"##### Return value of `fmin`\n", | |
"\n", | |
"Note that the return value from the `fmin` function is a numpy `array` which – for the example above – contains only one number as we have only one parameter (here *x*) to vary. In general, `fmin` can be used to find the minimum in a higher-dimensional parameter space if there are several parameters. In that case, the numpy array would contain those parameters that minimise the objective function. The objective function $f(x)$ has to return a scalar even if there are more parameters, i.e. even if $x$ is a vector as in $f(\\mathbf{x})$." | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Other numerical methods\n", | |
"-----------------------\n", | |
"\n", | |
"Scientific Python and Numpy provide access to a large number of other numerical algorithms including function interpolation, Fourier transforms, optimisation, special functions (such as Bessel functions), signal processing and filters, random number generation, and more. Start to explore `scipy`’s and `numpy`’s capabilities using the `help` function and the documentation provided on the web." | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"scipy.io: Scipy-input output\n", | |
"----------------------------\n", | |
"\n", | |
"Scipy provides routines to read and write Matlab `mat` files. Here is an example where we create a Matlab compatible file storing a (1x11) matrix, and then read this data into a numpy array from Python using the scipy Input-Output library:\n", | |
"\n", | |
"First we create a mat file in Octave (Octave is \\[mostly\\] compatible with Matlab):\n", | |
"\n", | |
"```octave\n", | |
"octave:1> a=-1:0.5:4\n", | |
"a =\n", | |
"Columns 1 through 6:\n", | |
" -1.0000 -0.5000 0.0000 0.5000 1.0000 1.5000 \n", | |
"Columns 7 through 11:\n", | |
" 2.0000 2.5000 3.0000 3.5000 4.0000\n", | |
"octave:2> save -6 octave_a.mat a %save as version 6\n", | |
"```" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Then we load this array within python:" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 12, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"from scipy.io import loadmat\n", | |
"mat_contents = loadmat('scipy/code/octave_a.mat')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 13, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"{'__globals__': [],\n", | |
" '__header__': b'MATLAB 5.0 MAT-file Platform: posix, Created on: Mon Aug 8 12:21:36 2016',\n", | |
" '__version__': '1.0',\n", | |
" 'a': array([[-1. , -0.5, 0. , 0.5, 1. , 1.5, 2. , 2.5, 3. , 3.5, 4. ]])}" | |
] | |
}, | |
"execution_count": 13, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"mat_contents" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 14, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"array([[-1. , -0.5, 0. , 0.5, 1. , 1.5, 2. , 2.5, 3. , 3.5, 4. ]])" | |
] | |
}, | |
"execution_count": 14, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"mat_contents['a']" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"The function `loadmat` returns a dictionary: the key for each item in the dictionary is a string which is the name of that array when it was saved in Matlab. The key is the actual array.\n", | |
"\n", | |
"A Matlab matrix file can hold several arrays. Each of those is presented by one key-value pair in the dictionary.\n", | |
"\n", | |
"Let’s save two arrays from Python to demonstrate that:" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 15, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"import scipy.io\n", | |
"import numpy as np\n", | |
"\n", | |
"# create two numpy arrays\n", | |
"a = np.linspace(0, 50, 11)\n", | |
"b = np.ones((4, 4))\n", | |
"\n", | |
"# save as mat-file\n", | |
"# create dictionary for savemat\n", | |
"tmp_d = {'a': a,\n", | |
" 'b': b}\n", | |
"scipy.io.savemat('data.mat', tmp_d)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"This program creates the file `data.mat`, which we can subsequently read using Matlab or here Octave:\n", | |
"\n", | |
" HAL47:code fangohr$ octave\n", | |
" GNU Octave, version 3.2.4\n", | |
" Copyright (C) 2009 John W. Eaton and others.\n", | |
" <snip>\n", | |
"\n", | |
" octave:1> whos\n", | |
" Variables in the current scope:\n", | |
"\n", | |
" Attr Name Size Bytes Class\n", | |
" ==== ==== ==== ===== ===== \n", | |
" ans 1x11 92 cell\n", | |
"\n", | |
" Total is 11 elements using 92 bytes\n", | |
"\n", | |
" octave:2> load data.mat\n", | |
" octave:3> whos\n", | |
" Variables in the current scope:\n", | |
"\n", | |
" Attr Name Size Bytes Class\n", | |
" ==== ==== ==== ===== ===== \n", | |
" a 11x1 88 double\n", | |
" ans 1x11 92 cell\n", | |
" b 4x4 128 double\n", | |
"\n", | |
" Total is 38 elements using 308 bytes\n", | |
"\n", | |
" octave:4> a\n", | |
" a =\n", | |
"\n", | |
" 0\n", | |
" 5\n", | |
" 10\n", | |
" 15\n", | |
" 20\n", | |
" 25\n", | |
" 30\n", | |
" 35\n", | |
" 40\n", | |
" 45\n", | |
" 50\n", | |
"\n", | |
" octave:5> b\n", | |
" b =\n", | |
"\n", | |
" 1 1 1 1\n", | |
" 1 1 1 1\n", | |
" 1 1 1 1\n", | |
" 1 1 1 1" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Note that there are other functions to read from and write to in formats as used by IDL, Netcdf and other formats in `scipy.io`.\n", | |
"\n", | |
"More → see [Scipy tutorial](http://docs.scipy.org/doc/scipy/reference/tutorial/io.html)." | |
] | |
} | |
], | |
"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.4.4" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment