I am using a logical sigmoid for an application. I compared times using the scipy.special , expit , compared to using the hyperbolic tangent sigmoid definition.
I found that the hyperbolic tangent was 3 times faster. What's going on here? I also tested the time on a sorted array to see if the result was different.
Here is an example that was run in IPython:
In [1]: from scipy.special import expit In [2]: myexpit = lambda x: 0.5*tanh(0.5*x) + 0.5 In [3]: x = randn(100000) In [4]: allclose(expit(x), myexpit(x)) Out[4]: True In [5]: timeit expit(x) 100 loops, best of 3: 15.2 ms per loop In [6]: timeit myexpit(x) 100 loops, best of 3: 4.94 ms per loop In [7]: y = sort(x) In [8]: timeit expit(y) 100 loops, best of 3: 15.3 ms per loop In [9]: timeit myexpit(y) 100 loops, best of 3: 4.37 ms per loop
Edit:
Information about the car:
- Ubuntu 16.04
- RAM: 7.4 GB
- Intel Core i7-3517U CPU @ 1.90GHz × 4
Numpy / Scipy Information:
In [1]: np.__version__ Out[1]: '1.12.0' In [2]: np.__config__.show() lapack_opt_info: libraries = ['openblas', 'openblas'] library_dirs = ['/usr/local/lib'] define_macros = [('HAVE_CBLAS', None)] language = c blas_opt_info: libraries = ['openblas', 'openblas'] library_dirs = ['/usr/local/lib'] define_macros = [('HAVE_CBLAS', None)] language = c openblas_info: libraries = ['openblas', 'openblas'] library_dirs = ['/usr/local/lib'] define_macros = [('HAVE_CBLAS', None)] language = c blis_info: NOT AVAILABLE openblas_lapack_info: libraries = ['openblas', 'openblas'] library_dirs = ['/usr/local/lib'] define_macros = [('HAVE_CBLAS', None)] language = c lapack_mkl_info: NOT AVAILABLE blas_mkl_info: NOT AVAILABLE In [3]: import scipy In [4]: scipy.__version__ Out[4]: '0.18.1'
source share