neurotools.util.functions module

Commonly used mathematical functions and high-precision (np.longdouble) versions of common constants.

neurotools.util.functions.slog(x, eps=3.7433921782255195601e-23, returntype=<class 'numpy.float64'>)[source]

“safe” natural logarithm function, clips values avoiding NaN and inf

neurotools.util.functions.sexp(x, limit=26.641747557046326023, returntype=<class 'numpy.float64'>)[source]

“safe” exponential function, clips values avoiding NaN and inf

neurotools.util.functions.sigmoid(x, limit=26.641747557046326023, returntype=<class 'numpy.float64'>)[source]

sigmoid function 1/(1+exp(-x))

neurotools.util.functions.inversesigmoid(x, returntype=<class 'numpy.float64'>)[source]

Inverse of sigmoid function 1/(1+exp(-x)), -[log(1-x)+log(x)]

neurotools.util.functions.dsigmoid(x, returntype=<class 'numpy.float64'>)[source]

Fist derivative of sigmoid

neurotools.util.functions.g(x, returntype=<class 'numpy.float64'>)[source]

Evaluates g(x)=log(1+exp(x)) as accurately as possible.

neurotools.util.functions.f(x, returntype=<class 'numpy.float64'>)[source]

evaluates f(x)=1/(1+exp(-x)) as accurately as possible

neurotools.util.functions.f1(x, returntype=<class 'numpy.float64'>)[source]

Fist derivative of sigmoid

neurotools.util.functions.f2(x, returntype=<class 'numpy.float64'>)[source]

Second derivative of sigmoid

(q - p) p q

neurotools.util.functions.npdf(mu, sigma, x)[source]

Univariate Gaussian probability density

Parameters:
  • mu (float, scalar or array-like) – Mean(s) of distribution(s)

  • sigma (float, scalar or array-like) – Standard deviation(s) of distribution(s)

  • x (float, scalar or array-like) – Points at which to evaluate distribution(s)

neurotools.util.functions.log_factorial(k)[source]

Returns the logarithm of a factorial by taking the sum of the logarithms of 1..N. Slow, but numerically more accurate than taking the logarithm of the factorial or using approximations.

k should be an integer.