pybaselines.utils.relative_difference

pybaselines.utils.relative_difference(old, new, norm_order=None)[source]

Calculates the relative difference, (norm(new-old) / norm(old)), of two values.

Used as an exit criteria in many baseline algorithms.

Parameters:
oldnumpy.ndarray or float

The array or single value from the previous iteration.

newnumpy.ndarray or float

The array or single value from the current iteration.

norm_orderint, optional

The type of norm to calculate. Default is None, which is l2 norm for arrays, abs for scalars.

Returns:
float

The relative difference between the old and new values.