Convenience and test functions

All the convenience functions are designed to facilitate a computational environment where the user does not need to worry about relative errors. The functions seem to be pointless at first sight, but behind their codes, there are state-of-the-art ideas that offer faster and more reliable results.

We have convenience functions beyond the ones defined in the NumPy libraries to find the solutions of trigonometric functions in degrees (cosdg, sindg, tandg, and cotdg); to compute angles in radians from their expressions in degrees, minutes, and seconds (radian); common powers (exp2 for 2**x, and exp10 for 10**x); and common functions for small values of the variable (log1p for log(1 + x), expm1 for exp(x) - 1, and cosm1 for cos(x) - 1).

For instance, in the following code snippet, the log1p function computes the natural logarithm of 1 + x. Why not simply add 1 to the value of x and then take the logarithm instead? Let's compare:

>>> import numpy
>>> import scipy.special
>>> a=scipy.special.exp10(-16)
>>> numpy.log(1+a)

The output is as follows:

0.0

Now let's use log1p() on a:

>>> scipy.special.log1p(a)

The output is as follows:

9.9999999999999998e-17

While the absolute error of the first computation is small, the relative error is 100 percent.

In the same way as Lena image is regarded as the performance test in image processing, we have a few functions that are used to test different algorithms in different scenarios.

For instance, it is customary to test minimization codes against the Rosenbrock's banana function (http://en.wikipedia.org/wiki/Rosenbrock_function):

Convenience and test functions

The corresponding optimization module, scipy.optimize, has a routine to accurately evaluate this function (rosen), its derivative (rosen_der), its Hessian matrix (rosen_hess), or the product of the latter with a vector (rosen_hess_prod).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.140.204