| |
- 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
|