INGOR
Public Member Functions | List of all members
ytBSpline Class Reference

B-Spline routines. More...

#include <math/ytBSpline.h>

Public Member Functions

void ytBSpline_designMatrix2 (const double *x, const int n, double *B, int *index, const int ndx, const int degree, double *work)
 Generates the design matrix for B-spline nonparametric regression. More...
 
void ytBSpline_designMatrix (const double *x, const int n, const double xl, const double xr, double *B, int *index, const int ndx, const int degree, double *work)
 Generates the design matrix for B-spline nonparametric regression. More...
 
void ytBSpline_Dk (const int m, const int k, double *D)
 Generates k-th order difference matrix. More...
 
void ytBSpline_K (int m, int k, double *K, double *work)
 Calculates Dk' Dk where Dk is the k-th order difference matrix. More...
 
double ytBSpline_det_K_plus (const double *K, const int m)
 Calculates |K|+. More...
 
void ytBSpline_syBtB (const double *B, const int *index, const int n, const int ndx, const int degree, double *BtB)
 Calculates the symmetric matrix of the multiplication B' B using the index vector set by ytBSpline_designMatrix(). More...
 
void ytBSpline_dsycopy (const double *X, double *Y, int m)
 Copies an upper symmetric matrix. More...
 
void ytBSpline_dxpy_mask (int n, double *x, const double *y, const char *mask)
 Calculates a vector-vector addition x <- x + y with a mask vector. More...
 
void ytBSpline_dxmy_mask (int n, double *x, const double *y, const char *mask)
 Calculates a vector-vector subtraction x <- x - y with a mask vector. More...
 
void ytBSpline_Mv20 (int n, const double *A, const double *b, double *c)
 A b c (M,n) x (n,1) -> (M,1) M=20.
 
void ytBSpline_printB (FILE *fp, const double *B, const int *index, int n, int ndx, int deg)
 Prints the design matrix. More...
 
double ytBSpline_gamma20 (double x, double xl, double xr, double *gamma)
 Calculates B-splines with its coefficients for a single value. More...
 

Detailed Description

B-Spline routines.

The main routine is ytBSpline_designMatrix() that generates the design matrix for the given set of values. By multiplying coeffients to the design matrix, you can obtain a smooth curve made of B-splines. Formaly, the curve can be expressed as a vector Y = B g where B is the n by M design matrix, gamma a M-vector of coefficients, and M the number of B-splines.

Many routines assume that the degree is 3 and M is 20. For example, the above equation can be calculated ytBSpline_Bx3().

Member Function Documentation

◆ ytBSpline_designMatrix()

void ytBSpline_designMatrix ( const double *  x,
const int  n,
const double  xl,
const double  xr,
double *  B,
int *  index,
const int  ndx,
const int  degree,
double *  work 
)

Generates the design matrix for B-spline nonparametric regression.

This generates the design metrix of B-splines.

Because only (degree + 1) B-splines cover a single value in x, the size of the design matrix requires only n by (degree + 1).

NaN values are acceptable in x. If so, NaNs are ignored.

The algorithm is based on Eilers and Marx (1996).

Parameters
[in]xvector of size n.
[in]nThe number of samples.
[in]xlminimum value of the input value range.
[in]xrmaximum value of the input value range.
[out]BRow major matrix of size n by (degree + 1), to which the generated design matrix is set.
[out]indexvector of size n to which values representing the first index of B-splines convering each value in x is set.
[in]ndxnumber of B-splines. The number of intervals for values in x is ndx - degree.
[in]degreedegree of B-splines.
workworking area of size ndx + 1 + n * (degree + 1).

◆ ytBSpline_designMatrix2()

void ytBSpline_designMatrix2 ( const double *  x,
const int  n,
double *  B,
int *  index,
const int  ndx,
const int  degree,
double *  work 
)

Generates the design matrix for B-spline nonparametric regression.

This generates the design metrix of B-splines.

Because only (degree + 1) B-splines cover a single value in x, the size of the design matrix requires only n by (degree + 1).

NaN values are acceptable in x. If so, NaNs are ignored.

The algorithm is based on Eilers and Marx (1996).

Parameters
[in]xvector of size n.
[in]nThe number of samples.
[out]BRow major matrix of size n by (degree + 1), to which the generated design matrix is set.
[out]indexvector of size n to which values representing the first index of B-splines convering each value in x is set.
[in]ndxnumber of B-splines. The number of intervals for values in x is ndx - degree.
[in]degreedegree of B-splines.
workworking area of size ndx + 1 + n * (degree + 1).

◆ ytBSpline_det_K_plus()

double ytBSpline_det_K_plus ( const double *  K,
const int  m 
)

Calculates |K|+.

Parameters
[in]KMatrix calculated by BSpline_K().
[in]msize of K.
Returns
|K|+.

◆ ytBSpline_Dk()

void ytBSpline_Dk ( const int  m,
const int  k,
double *  D 
)

Generates k-th order difference matrix.

Parameters
[in]mthe size of matrix to generate.
[in]kthe order of the difference matrix to generate.
[out]D(m - k) x m difference matrix.

◆ ytBSpline_dsycopy()

void ytBSpline_dsycopy ( const double *  X,
double *  Y,
int  m 
)

Copies an upper symmetric matrix.

Parameters
[in]X
[out]Y
[in]msize (the number of rows) of the matrix.

◆ ytBSpline_dxmy_mask()

void ytBSpline_dxmy_mask ( int  n,
double *  x,
const double *  y,
const char *  mask 
)

Calculates a vector-vector subtraction x <- x - y with a mask vector.

Parameters
n
[in,out]x
[in]y
[in]mask

◆ ytBSpline_dxpy_mask()

void ytBSpline_dxpy_mask ( int  n,
double *  x,
const double *  y,
const char *  mask 
)

Calculates a vector-vector addition x <- x + y with a mask vector.

The i-th elements where mask has 0 are ignored.

Parameters
n
[in,out]x
[in]y
[in]mask

◆ ytBSpline_gamma20()

double ytBSpline_gamma20 ( double  x,
double  xl,
double  xr,
double *  gamma 
)

Calculates B-splines with its coefficients for a single value.

This assumes the fixed 20 B-splines for the range from xl to xr.

Parameters
x
xlleft most (minimum) value of the range.
xrright most (maximum) value of the range.
gamma20 length array of coefficients.

◆ ytBSpline_K()

void ytBSpline_K ( int  m,
int  k,
double *  K,
double *  work 
)

Calculates Dk' Dk where Dk is the k-th order difference matrix.

Parameters
msize of the matrix.
kdegree (order) of the difference matrix.
Km x m matrix.
workAt least (m - k) x m size working area. NULL is acceptable. If so, this function allocates dynamically the working area and frees it on exit.

◆ ytBSpline_printB()

void ytBSpline_printB ( FILE *  fp,
const double *  B,
const int *  index,
int  n,
int  ndx,
int  deg 
)

Prints the design matrix.

Parameters
fpfile stream pointer to output.
Brow-major n by deg + 1 - design matrix returned by ytBSpline_designMatrix().
indexindex vector returned by ytBSpline_designMatrix().
nthe number of samples.
ndxthe number of B-splines.
degdegree of B-splines.

◆ ytBSpline_syBtB()

void ytBSpline_syBtB ( const double *  B,
const int *  index,
const int  n,
const int  ndx,
const int  degree,
double *  BtB 
)

Calculates the symmetric matrix of the multiplication B' B using the index vector set by ytBSpline_designMatrix().

Note: only upper triangle elements are filled.

Parameters
[in]Bdesign matrix of size n x degree + 1, calculated by BSpline_design_matrix().
[in]indexindex vector of size n, calculated by BSpline_design_matrix().
[in]nnumber of samples
[in]ndxnumber of B-splines.
[in]degreedegree of B-splines.
[out]BtBmatrix of size ndx x ndx used to put the results.

The documentation for this class was generated from the following file: