math_utils.py

math_utils.py#

Smooth functions and their derivatives.

aviary.utils.math_utils.dSigmoidXdx(x, x0, mu=1.0)[source]

Derivative of sigmoid function.

Parameters:
  • x (float or array) – independent variable

  • x0 (float) – the center of symmetry. When x = x0, sigmoidX = 1/2.

  • mu (float) – steepness parameter.

Returns:

smoothed derivative value from input parameter x.

Return type:

float or array

aviary.utils.math_utils.d_smooth_int_tanh(x, mu=10.0)[source]

Smooth approximation of int(x) using tanh. Returns (y, dy_dx).

aviary.utils.math_utils.d_smooth_max(x, b, mu=10.0)[source]

Derivative of function smooth_min(x).

Parameters:
  • array-like) (b (float or)

  • array-like)

  • (float) (mu)

Returns:

float or array-like

Return type:

The smooth approximation of derivative of min(x, b).

aviary.utils.math_utils.d_smooth_min(x, b, mu=100.0)[source]

Derivative of function smooth_min(x).

Parameters:
  • array-like) (b (float or)

  • array-like)

  • (float) (mu)

Returns:

float or array-like

Return type:

The smooth approximation of derivative of min(x, b).

aviary.utils.math_utils.deg2rad(d)[source]

Complex step safe deg2rad.

aviary.utils.math_utils.dydx_sin_int(val)[source]

Define the derivative (dy/dx) of sin_int, at x = val.

aviary.utils.math_utils.dydx_sin_int4(val)[source]

Define the derivative (dy/dx) of sin_int4, at x = val.

aviary.utils.math_utils.rad2deg(r)[source]

Complex step safe rad2deg.

aviary.utils.math_utils.round_it(x, sig=None)[source]

Round a float to a specified significance. If the number is equal to zero, “0” will be returned, regardless of the number of significant digits specified If the number is NaN, directly returns it (stays NaN).

Parameters:
  • x (str or float) – the float that needs to be rounded.

  • sig (int) – the number of significant digits to include (If this is unspecified, the number will be rounded to two decimal places).

Returns:

  • The rounded number, or provided string if not convertible to float, or original

  • number if it is NaN

aviary.utils.math_utils.sigmoidX(x, x0, mu=1.0)[source]

Sigmoid used to smoothly transition between piecewise functions.

Parameters:
  • x (float or array) – independent variable

  • x0 (float) – the center of symmetry. When x = x0, sigmoidX = 1/2.

  • mu (float) – steepness parameter.

Returns:

smoothed value from input parameter x.

Return type:

float or array

aviary.utils.math_utils.sin_int(val)[source]

Define one step in approximating the ‘int’ function with a smooth, differentialbe function.

aviary.utils.math_utils.sin_int4(val)[source]

Define a smooth, differentialbe approximation to the ‘int’ function.

aviary.utils.math_utils.smooth_int_tanh(x, mu=10.0)[source]

Smooth approximation of int(x) using tanh.

aviary.utils.math_utils.smooth_max(x, b, mu=10.0)[source]

Smooth approximation of the min function using the log-sum-exp trick.

Parameters:
  • array-like) (b (float or)

  • array-like)

  • (float) (mu)

Returns:

float or array-like

Return type:

The smooth approximation of max(x, b).

aviary.utils.math_utils.smooth_min(x, b, mu=100.0)[source]

Smooth approximation of the min function using the log-sum-exp trick.

Parameters:
  • array-like) (b (float or)

  • array-like)

  • (float) (mu)

Returns:

float or array-like

Return type:

The smooth approximation of min(x, b).