npsolve.soft_functions module¶
Created on Fri May 15 16:17:04 2020
@author: Reuben
These functions can be used to prevent discontinuities, which can cause trouble for numerical methods.
-
npsolve.soft_functions.
above
(x, limit=0.0, scale=0.0001)¶ A smooth step from 0 below a limit to 1 above it
Parameters: - x (int, float, ndarray) – The value(s)
- limit (float) – [OPTIONAL] The value to step at. Defaults to 0.
- scale (float) – [OPTIONAL] A scale factor for the softening
Returns: Value(s) between 0 and 1
Return type: float, ndarray
See also
soft_step
-
npsolve.soft_functions.
below
(x, limit=0.0, scale=0.0001)¶ A smooth step from 1 below a limit to 0 above it
Parameters: - x (int, float, ndarray) – The value(s)
- limit (float) – [OPTIONAL] The value to step at. Defaults to 0.
- scale (float) – [OPTIONAL] A scale factor for the softening
Returns: Value(s) between 0 and 1
Return type: float, ndarray
See also
soft_step
-
npsolve.soft_functions.
ceil
(x, limit=0.0, scale=0.0001)¶ Limit value to a maximum softly to to prevent discontinuous gradient
Parameters: - x (int, float, ndarray) – The value(s) to soft limit
- limit (float) – [OPTIONAL] The value to limit at. Defaults to 0.
- scale (float) – [OPTIONAL] A scale factor for the softening
Returns: The limited value(s)
Return type: float, ndarray
See also
soft_limit
-
npsolve.soft_functions.
clip
(x, lower, upper, scale=0.0001)¶ Limit value to a range softly to to prevent discontinuous gradient
Parameters: - x (int, float, ndarray) – The value(s) to soft limit
- lower (float) – The lower threshold
- upper (float) – The upper threshold
- scale – A scale factor for the softening
Returns: The limited value(s)
Return type: float, ndarray
See also
soft_limit
-
npsolve.soft_functions.
floor
(x, limit=0.0, scale=0.0001)¶ Limit value to a minimum softly to to prevent discontinuous gradient
Parameters: - x (int, float, ndarray) – The value(s) to soft limit
- limit (float) – [OPTIONAL] The value to limit at. Defaults to 0.
- scale (float) – [OPTIONAL] A scale factor for the softening
Returns: The limited value(s)
Return type: float, ndarray
See also
soft_limit
-
npsolve.soft_functions.
gaussian
(x, center=0.0, scale=0.0001)¶ A gaussian function, with a peak of 1.0
Parameters: - x (int, float, ndarray) – The value(s)
- center (float) – [OPTIONAL] The x-position of the peak center
- scale (float) – [OPTIONAL] A scale factor for the curve.
-
npsolve.soft_functions.
lim
(x, limit=0.0, side=1, scale=0.0001)¶ Limit the value softly to prevent discontinuous gradient
Parameters: - x (int, float, ndarray) – The value(s) to soft limit
- limit (float) – [OPTIONAL] The value to limit at. Defaults to 0.
- side (int) – [OPTIONAL] 1 for min, -1 for max. Defaults to 1.
- scale (float) – [OPTIONAL] A scale factor for the softening
Returns: The limited value(s)
Return type: float, ndarray
Note
This function uses a softplus function to perform smoothing. See https://en.wikipedia.org/wiki/Activation_function. Values for the calculation are clipped to 700 avoid overflow errors, as the max value for a float is exp(709.782).
-
npsolve.soft_functions.
negdiff
(x, limit=0.0, scale=0.0001)¶ Negative-only difference (difference below limit to 0 above limit)
Parameters: - x (int, float, ndarray) – The value(s) to soft limit
- limit (float) – [OPTIONAL] The value to limit at. Defaults to 0.
- scale (float) – [OPTIONAL] A scale factor for the softening
Returns: The limited value(s)
Return type: float, ndarray
See also
soft_limit
-
npsolve.soft_functions.
outside
(x, lower, upper, scale=0.0001)¶ Steps smoothly from 1 outside a range to 0 inside it
Parameters: - x (int, float, ndarray) – The value(s)
- lower (float) – The lower threshold
- upper (float) – The upper threshold
- scale (float) – [OPTIONAL] A scale factor for the softening
Returns: Value(s) between 0 and 1
Return type: float, ndarray
See also
soft_step
-
npsolve.soft_functions.
posdiff
(x, limit=0.0, scale=0.0001)¶ Positive-only difference (0 below limit to difference above limit)
Parameters: - x (int, float, ndarray) – The value(s) to soft limit
- limit (float) – [OPTIONAL] The value to limit at. Defaults to 0.
- scale (float) – [OPTIONAL] A scale factor for the softening
Returns: The limited value(s)
Return type: float, ndarray
See also
soft_limit
-
npsolve.soft_functions.
sign
(x, scale=0.0001)¶ A smooth step from -1 below 0 to +1 above it
Parameters: - x (int, float, ndarray) – The value(s)
- scale (float) – [OPTIONAL] A scale factor for the softening
Returns: Value(s) between 0 and 1
Return type: float, ndarray
Note
This function uses a sigmoid function to perform smoothing. See https://en.wikipedia.org/wiki/Sigmoid_function. Values for the calculation are clipped to avoid overflow errors.
-
npsolve.soft_functions.
step
(x, limit=0.0, side=1, scale=0.0001)¶ A smooth step to prevent discontinuous gradient
Parameters: - x (int, float, ndarray) – The value(s)
- limit (float) – [OPTIONAL] The value to step at. Defaults to 0.
- side (int) – [OPTIONAL] 1 for min, -1 for max. Defaults to 1.
- scale (float) – [OPTIONAL] A scale factor for the softening
Returns: Value(s) between 0 and 1
Return type: float, ndarray
Note
This function uses a sigmoid function to perform smoothing. See https://en.wikipedia.org/wiki/Sigmoid_function. Values for the calculation are clipped to avoid overflow errors.
-
npsolve.soft_functions.
within
(x, lower, upper, scale=0.0001)¶ Steps smoothly from 0 outside a range to 1 inside it
Parameters: - x (int, float, ndarray) – The value(s)
- lower (float) – The lower threshold
- upper (float) – The upper threshold
- scale (float) – [OPTIONAL] A scale factor for the softening
Returns: Value(s) between 0 and 1
Return type: float, ndarray
See also
soft_step