Functions
AMA_UnvLstsqr.c File Reference
#include <AMA.h>

Functions

long int AMA_UnvLstsqr (AMA_OPTIONS *options, long int n, double *x, double *z, double *wht, long int degree, long int mlamda, double *lamda, double theta, AMA_SPLINE **spline)
 Least Squares Approximation of Univariate Data More...
 

Function Documentation

long int AMA_UnvLstsqr ( AMA_OPTIONS options,
long int  n,
double *  x,
double *  z,
double *  wht,
long int  degree,
long int  mlamda,
double *  lamda,
double  theta,
AMA_SPLINE **  spline 
)

Least Squares Approximation of Univariate Data

For a given set of data $(x_\ell,z_\ell)$ and weights $w_\ell$, for $\ell=1,\ldots,N$, this function employs cnspla to compute the spline

\[ s(x) = \sum_{j=1}^{m}\alpha_jB_{d,j}(x|{\bf\Lambda}) \]

that minimizes

\[ (1.0-\theta)\sum_\ell^N w_\ell ( s(x_\ell) - z_\ell )^2 + \theta \int_{\lambda_1}^{\lambda_{m+d+1}}\left( s^{(2)}(x) \right)^2 dx \]

for $0.0\le\theta< 1.0$. In the above definition of $s(x)$ the $\alpha_j$, for $j=1,\ldots,m$, are the coefficients of the $m$ univariate B-splines $B_{d,j}(x|{\bf\Lambda})$ of degree $1 \le d \le 5$ which are based on the knot vector ${\bf\Lambda}\in{\rm R}^M$ given as

\[ {\bf\Lambda} = ( \lambda_1,\cdots,\lambda_{d+1}, \lambda_{d+2}, \cdots, \lambda_m, \lambda_{m+1},\cdots,\lambda_{m+d+1} )^T \]

where the knots $\lambda_i$ must satisfy the conditions

  • $\lambda_1 = \ldots = \lambda_{d+1}$;
  • $\lambda_i \le \lambda_{i+1}$, for $1\le i\le m+d$;
  • $\lambda_i < \lambda_{i+d+1}$, for $1\le i\le m$;
  • $\lambda_{m+1} = \ldots = \lambda_{m+d+1}$.

If the knot vector ${\bf\Lambda}$ is represented by its distinct knot vector

\[ {\bf\rm K}^{{\bf\Lambda}} = ( \kappa_1, \kappa_2, \cdots, \kappa_{m^d-1}, \kappa_{m^d} )^T \]

and its knot multiplicity vector

\[ {\bf\rm H}^{{\bf\Lambda}} = ( \eta_1, \eta_2, \cdots, \eta_{m^d-1}, \eta_{m^d} )^T \]

then the aforementioned conditions are

  • $\kappa_i < \kappa_{i+1}$, for $1\le i\le m^d - 1$;
  • $\eta_i \le d + 1$, for $2\le i\le m^d-1$;
  • $\eta_1 = \eta_{m^d} = d+1$.

Also the first and last distinct knots must satisfy the conditions $\kappa_1\le x_1$ and $\kappa_{m^d}\ge x_N$, respectively. In this case the number of knots is $M = m + d + 1$.

For convenience this function does not require the definition of the $d+1$ order knots at the left and right hand endpoints and also accepts the knot vector ${\bf\Lambda}^o\in{\rm R}^M$

\[ {\bf\Lambda}^o = ( \lambda_{d+1}, \lambda_{d+2}, \cdots, \lambda_m, \lambda_{m+1} )^T \]

where the knots $\lambda_i$ satisfy the conditions

  • $\lambda_i \le \lambda_{i+1}$, for $d+2\le i\le m-1$;
  • $\lambda_i < \lambda_{i+d+1}$, for $d+1\le i\le m-d$;
  • $\lambda_{d+1} < \lambda_{d+2}$ and $\lambda_m < \lambda_{m+1}$.

If the knot vector ${\bf\Lambda}^o$ is represented by its distinct knot vector

\[ {\bf\rm K}^{{\bf\Lambda}^o} = ( \kappa_1, \kappa_2, \cdots, \kappa_{m^d-1}, \kappa_{m^d} )^T \]

and its knot multiplicity vector

\[ {\bf\rm H}^{{\bf\Lambda}^o} = ( \eta_1, \eta_2, \cdots, \eta_{m^d-1}, \eta_{m^d} )^T \]

then the aforementioned conditions are

  • $\kappa_i < \kappa_{i+1}$, for $1\le i\le m^d - 1$;
  • $\eta_i \le d + 1$, for $2\le i\le m^d-1$;
  • $\eta_1 = \eta_{m^d} = 1$.

As before, the first and last distinct knots must satisfy the conditions $\kappa_1\le x_1$ and $\kappa_{m^d}\ge x_N$, respectively. In this case the number of knots is $M = m - d + 1$.

Additionally, the spline $s(x)$ is subject to the bounds

\[ \alpha_l \le s(x) \le \alpha_u \]

where $\alpha_l=-\alpha_\infty$, $\alpha_u=\alpha_\infty$ and $\alpha_\infty$ equals AMA_SplineInfbnd(). By default the spline is unbounded but finite bounds can be set with AMA_OptionsSetBounds().

Depending on the number and distribution of the knots relative to the independent variable data it is possible for the least squares approximation problem to have a non-unique solution. Hence, this function provides the capability of performing a minimum norm optimization subsequent to computing the least squares approximation. The minimum norm optimization computes an alternate spline $\bar s({\bf X})$ by minimizing

\[ \int_{\lambda_1}^{\lambda_{m+d+1}}\left(\bar s^{(2)}(x)\right)^2dx \]

subject to the approximation constraints

\[ z_l - \epsilon_\ell \le \bar s(x_\ell) \le z_l + \epsilon_\ell, \]

for $\ell=1,\ldots,N$, where $\epsilon_l = s(x_\ell)-z_\ell$ and $s(x_\ell)$ is the least squares approximation. These constraints insure the condition

\[ \sum_\ell^N w_\ell ( \bar s(x_\ell) - z_\ell )^2 \le \sum_\ell^N w_\ell ( s(x_\ell) - z_\ell )^2, \]

that is, the minimum norm optimization does not increase the least squares error.

This function does the following:

  • Checks input parameters for validity, see AMA_UnvInputCheck().
  • Defines the spline $s(x)$ based on the knot vector ${\bf\Lambda}$ or ${\bf\Lambda}^o$.
  • Invokes cnspla to compute a least squares spline approximation.
  • Invokes cnspla to perform a minimum norm optimization.
  • Stores approximation into spline.
Note
By default the spline coefficients are initialized to zero but a different initial value for the spline coefficients can be set with AMA_OptionsSetCoefficients().
By default the spline is unbounded but finite bounds can be set with AMA_OptionsSetBounds().
By default the minimum norm optimization is not performed but it can be enabled with AMA_OptionsSetMinimumNorm().
The penalty term and minimum norm optimization options are mutually exclusive; that is, the minimum norm optimization is not performed if $\theta > 0.0$.
Parameters
options[in] Pointer to AMA_OPTIONS. Must be initialized with AMA_Options() prior to calling AMA_UnvLstsqr().
n[in] The number of data points $N$. Must satisfy n $\ge 2$.
x[in] Array of size n containing the independent variable data $x_\ell$, for $\ell=1,\ldots,N$. Must be in ascending order.
z[in] Array of size n containing the dependent variable data $z_\ell$, for $\ell=1,\ldots,N$.
wht[in] Array of size n containing the weights $w_\ell$, for $\ell=1,\ldots,N$. Must satisfy $w_\ell\ge 0.0$ for all $\ell=1,\ldots,N$. If wht = NULL, then this function uses $w_\ell = 1.0$ for all $\ell=1,\ldots,N$.
degree[in] The degree $d$. Must satisfy $1\le$ degree $\le 5$.
mlamda[in] The number of knots $M$. Must satisfy mlamda $\ge 2$.
lamda[in] Array of size mlamda containing the knot vector ${\bf\Lambda}$ or ${\bf\Lambda}^o$.
theta[in] The penalty term weight $\theta$. Must satisfy $0.0\le$ theta $< 1.0$.
spline[out] Pointer to AMA_SPLINE pointer containing the least squares spline approximation. Must satisfy spline $\ne$ NULL.
Returns
Success/Error Code.

User Callable Function - Documented 101715