regularsmooth

Smooth data by regularization.
 
Implementation Notes
--------------------
    Smooth data by regularization as described in [1]. Optimal values
    for the regularization parameter, lambda, can be calulated using
    the generalized cross-validation method described in [2] or by
    constraining the standard deviation between the smoothed and
    measured data as described in [3]. Both methods for calculating
    lambda are reviewed in [1].
 
    Smoothing with constraints is also implemented, but without the
    features for determining an optimal value for the regularizaiton
    parameter. Requires the cvxopt module (constrained smoothing is
    disabled if cvxopt is not installed).
 
References
----------
    [1] Comput. Chem. Eng. (2010) 34, 467
    [2] Anal. Chem. (2003) 75, 3631
    [3] AIChE J. (2006) 52, 325

 
Modules
       
cvxopt
cvxopt.solvers
numpy
scipy.optimize

 
Functions
       
calc_derivative(x, y, d=1)
Return order `d` derivative
derivative_matrix(x, d=1)
Return order `d` derivative matrix.
smooth_data(x, y, d=2, lmbd=None, derivative=0, xhat=None, stdev=None, lmbd_guess=1.0, weights=None, relative=False, midpointrule=False)
Return smoothed y-values and optimal regularization parameter.
 
Smooths the `y`-values of 1D data by Tikhonov regularization. Also, return 
scaled regularization parameter `lmbd` used for smoothing when not provided.
 
If neither the regularization parameter, `lmbd`, nor the standard deviation 
`stdev` are provided, then use generalized cross-validation to determine the 
optimal value for the regularization parameter.
 
Parameters
----------
x : 1D array
    Data x-values.
y : 1D array
    Data y-values.
 
Optional Parameters
-------------------
xhat : 1D array
    A vector of x-values to use for the smooth curve; must be monotonically
    increasing.
derivative : int
    Return derivative of given order. The given value is added to the 
    smoothing derivative, `d`, such that the returned derivative has the 
    smoothness given by the input to `d`.
d : int
    Derivative used to calculate roughness. When `d = 2`, the 2nd derivative 
    (i.e. the curvature) of the data is used to calculate roughness.
stdev : float
    When provided, determine optimal value for lambda by matching the 
    provided value with the standard deviation of yhat-y; if the option 
    'relative' is True, then a relative standard deviation is inferred.
lmbd : float
    Scaled regularization parameter; larger values give smoother results.
lmbd_guess : float
    The initial value for lambda used in the iterative minimization
    algorithm to find the optimal value.
weights : 1D array
    A vector of weighting values for fitting each point in the data.
relative : bool
    Use relative differences for the goodness of fit term.
midpointrule : bool
    Use the midpoint rule for the integration terms rather than a
    direct sum; this option conflicts with the option "xhat".
 
Returns
-------
y_smooth : 1D array
    The smooth y-values
lmbd : float, optional
    'Optimal' scaled regularization parameter. Returned unless it is 
    provided as an input parameter.
 
Example
--------
>>> import numpy as np
>>> import scikits.datasmooth as ds
>>> import matplotlib.pyplot as plt
>>> npts = 100
>>> x = np.linspace(0,2*np.pi,npts)
>>> y = np.sin(x)
>>> y = y + 1e-1*np.random.randn(npts)
>>> yh,lmbd = ds.smooth_data (x, y, d=4, stdev=1e-1)
>>> plt.plot(x,y,'o',x,yh)
smooth_data_constr(x, y, d, lmbd, inequality=None, equality=None, xhat=None, weights=None, relative=False, midpointrule=False)
Smooths y vs. x values by Tikhonov regularization. This version
assumes that constraints are provided, hence a quadratic program
iterative method is used to find the solution.  In addition to x
and y, required input paramters includes the smoothing derivative
d and the regularization parameter lmbd.  Determination of the
optimal regularization parameter is not implemented.
 
Optional parameters
-------------------
inequality : tuple of numpy arrays (Ain, bin)
    Inequality constraints, i.e. Ain*yhat <= bin.
equality : tuple of numpy arrays (Aeq, beq)
    Equality constraints, i.e. Aeq*yhat = beq.
xhat : 1D array
    A vector of x-values to use for the smooth curve; must be
    monotonically increasing.
weights : 1D array
    A vector of weighting values for fitting each point in the data.
relative : bool
    Use relative differences for the goodnes of fit term
midpointrule : bool
    Use the midpoint rule for the integration terms rather than a
    direct sum; this option conflicts with the option "xhat"
 
Returns
-------
yhat : 1D array
    The smooth y-values

 
Data
        __all__ = ['smooth_data', 'smooth_data_constr', 'fmin_options', 'calc_derivative', 'derivative_matrix']
fmin_options = {'disp': False, 'ftol': 9.9999999999999995e-07, 'maxfun': 50, 'xtol': 0.01}