_total_variation_regularization

This module implements some common total variation regularization methods

pynumdiff.total_variation_regularization._total_variation_regularization.acceleration(x, dt, params, options=None)

Use convex optimization (cvxpy) to solve for the acceleration total variation regularized derivative. Default solver is MOSEK: https://www.mosek.com/

Parameters
  • x (np.array (float)) – array of time series to differentiate

  • dt (float) – time step size

  • params (list (float) or float) – [gamma], where gamma (float) is the regularization parameter or if ‘iterate’ in options: [gamma, num_iterations]

  • options (dict {'solver': SOLVER}, optional) – {‘solver’: SOLVER} SOLVER options include: ‘MOSEK’ and ‘CVXOPT’, in testing, ‘MOSEK’ was the most robust.

Returns

a tuple consisting of:

  • x_hat: estimated (smoothed) x

  • dxdt_hat: estimated derivative of x

Return type

tuple -> (np.array, np.array)

pynumdiff.total_variation_regularization._total_variation_regularization.iterative_velocity(x, dt, params, options=None)

Use an iterative solver to find the total variation regularized 1st derivative. See __chartrand_tvregdiff__.py for details, author info, and license Methods described in: Rick Chartrand, “Numerical differentiation of noisy, nonsmooth data,” ISRN Applied Mathematics, Vol. 2011, Article ID 164564, 2011. Original code (MATLAB and python): https://sites.google.com/site/dnartrahckcir/home/tvdiff-code

Parameters
  • x (np.array (float)) – array of time series to differentiate

  • dt (float) – time step size

  • params (list (int, float)) –

    a list consisting of:

    • iterations: Number of iterations to run the solver. More iterations results in blockier derivatives, which approach the convex result

    • gamma: Regularization parameter.

  • options (dict {'cg_maxiter': (int), 'scale': (string)}, optional) –

    a dictionary with 2 key value pairs

    • ’cg_maxiter’: Max number of iterations to use in scipy.sparse.linalg.cg. Default is None, results in maxiter = len(x). This works well in our test examples.

    • ’scale’: This method has two different numerical options. From __chartrand_tvregdiff__.py: ‘large’ or ‘small’ (case insensitive). Default is ‘small’. ‘small’ has somewhat better boundary behavior, but becomes unwieldly for data larger than 1000 entries or so. ‘large’ has simpler numerics but is more efficient for large-scale problems. ‘large’ is more readily modified for higher-order derivatives, since the implicit differentiation matrix is square.

Returns

a tuple consisting of:

  • x_hat: estimated (smoothed) x

  • dxdt_hat: estimated derivative of x

Return type

tuple -> (np.array, np.array)

pynumdiff.total_variation_regularization._total_variation_regularization.jerk(x, dt, params, options=None)

Use convex optimization (cvxpy) to solve for the jerk total variation regularized derivative. Default solver is MOSEK: https://www.mosek.com/

Parameters
  • x (np.array (float)) – array of time series to differentiate

  • dt (float) – time step size

  • params (list (float) or float) – [gamma], where gamma (float) is the regularization parameter or if ‘iterate’ in options: [gamma, num_iterations]

  • options (dict {'solver': SOLVER}, optional) – {‘solver’: SOLVER} SOLVER options include: ‘MOSEK’ and ‘CVXOPT’, in testing, ‘MOSEK’ was the most robust.

Returns

a tuple consisting of:

  • x_hat: estimated (smoothed) x

  • dxdt_hat: estimated derivative of x

Return type

tuple -> (np.array, np.array)

pynumdiff.total_variation_regularization._total_variation_regularization.jerk_sliding(x, dt, params, options=None)

Use convex optimization (cvxpy) to solve for the jerk total variation regularized derivative. Default solver is MOSEK: https://www.mosek.com/

Parameters
  • x (np.array (float)) – array of time series to differentiate

  • dt (float) – time step size

  • params (list (float) or float) – [gamma], where gamma (float) is the regularization parameter or if ‘iterate’ in options: [gamma, num_iterations]

  • options (dict {'solver': SOLVER}, optional) – {‘solver’: SOLVER} SOLVER options include: ‘MOSEK’ and ‘CVXOPT’, in testing, ‘MOSEK’ was the most robust.

Returns

a tuple consisting of:

  • x_hat: estimated (smoothed) x

  • dxdt_hat: estimated derivative of x

Return type

tuple -> (np.array, np.array)

pynumdiff.total_variation_regularization._total_variation_regularization.smooth_acceleration(x, dt, params, options=None)

Use convex optimization (cvxpy) to solve for the acceleration total variation regularized derivative. And then apply a convolutional gaussian smoother to the resulting derivative to smooth out the peaks. The end result is similar to the jerk method, but can be more time-efficient.

Default solver is MOSEK: https://www.mosek.com/

Parameters
  • x (np.array of floats, 1xN) – time series to differentiate

  • dt (float) – time step

  • params (list -> [float, int]) – list with values [gamma, window_size], where gamma (float) is the regularization parameter, window_size (int) is the window_size to use for the gaussian kernel

  • options (dict {'solver': SOLVER}) – a dictionary indicating which SOLVER option to use, ie. ‘MOSEK’ or ‘CVXOPT’, in testing, ‘MOSEK’ was the most robust.

Returns

a tuple consisting of: - x_hat: estimated (smoothed) x - dxdt_hat: estimated derivative of x

Return type

tuple -> (np.array, np.array)

pynumdiff.total_variation_regularization._total_variation_regularization.velocity(x, dt, params, options=None)

Use convex optimization (cvxpy) to solve for the velocity total variation regularized derivative. Default solver is MOSEK: https://www.mosek.com/

Parameters
  • x (np.array (float)) – array of time series to differentiate

  • dt (float) – time step size

  • params (list (float) or float) – [gamma], where gamma (float) is the regularization parameter or if ‘iterate’ in options: [gamma, num_iterations]

  • options (dict {'solver': SOLVER}, optional) – {‘solver’: SOLVER} SOLVER options include: ‘MOSEK’ and ‘CVXOPT’, in testing, ‘MOSEK’ was the most robust.

Returns

a tuple consisting of:

  • x_hat: estimated (smoothed) x

  • dxdt_hat: estimated derivative of x

Return type

tuple -> (np.array, np.array)