INGOR
|
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. | |
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. | |
void | ytBSpline_Dk (const int m, const int k, double *D) |
Generates k-th order difference matrix. | |
void | ytBSpline_K (int m, int k, double *K, double *work) |
Calculates Dk' Dk where Dk is the k-th order difference matrix. | |
double | ytBSpline_det_K_plus (const double *K, const int m) |
Calculates |K|+. | |
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(). | |
void | ytBSpline_dsycopy (const double *X, double *Y, int m) |
Copies an upper symmetric matrix. | |
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. | |
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. | |
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. | |
double | ytBSpline_gamma20 (double x, double xl, double xr, double *gamma) |
Calculates B-splines with its coefficients for a single value. | |
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().
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).
[in] | x | vector of size n. |
[in] | n | The number of samples. |
[in] | xl | minimum value of the input value range. |
[in] | xr | maximum value of the input value range. |
[out] | B | Row major matrix of size n by (degree + 1), to which the generated design matrix is set. |
[out] | index | vector of size n to which values representing the first index of B-splines convering each value in x is set. |
[in] | ndx | number of B-splines. The number of intervals for values in x is ndx - degree. |
[in] | degree | degree of B-splines. |
work | working area of size ndx + 1 + n * (degree + 1). |
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).
[in] | x | vector of size n. |
[in] | n | The number of samples. |
[out] | B | Row major matrix of size n by (degree + 1), to which the generated design matrix is set. |
[out] | index | vector of size n to which values representing the first index of B-splines convering each value in x is set. |
[in] | ndx | number of B-splines. The number of intervals for values in x is ndx - degree. |
[in] | degree | degree of B-splines. |
work | working area of size ndx + 1 + n * (degree + 1). |
double ytBSpline_det_K_plus | ( | const double * | K, |
const int | m | ||
) |
Calculates |K|+.
[in] | K | Matrix calculated by BSpline_K(). |
[in] | m | size of K. |
void ytBSpline_Dk | ( | const int | m, |
const int | k, | ||
double * | D | ||
) |
Generates k-th order difference matrix.
[in] | m | the size of matrix to generate. |
[in] | k | the order of the difference matrix to generate. |
[out] | D | (m - k) x m difference matrix. |
void ytBSpline_dsycopy | ( | const double * | X, |
double * | Y, | ||
int | m | ||
) |
Copies an upper symmetric matrix.
[in] | X | |
[out] | Y | |
[in] | m | size (the number of rows) of the matrix. |
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.
n | ||
[in,out] | x | |
[in] | y | |
[in] | 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.
n | ||
[in,out] | x | |
[in] | y | |
[in] | mask |
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.
x | |
xl | left most (minimum) value of the range. |
xr | right most (maximum) value of the range. |
gamma | 20 length array of coefficients. |
void ytBSpline_K | ( | int | m, |
int | k, | ||
double * | K, | ||
double * | work | ||
) |
Calculates Dk' Dk where Dk is the k-th order difference matrix.
m | size of the matrix. |
k | degree (order) of the difference matrix. |
K | m x m matrix. |
work | At 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. |
void ytBSpline_printB | ( | FILE * | fp, |
const double * | B, | ||
const int * | index, | ||
int | n, | ||
int | ndx, | ||
int | deg | ||
) |
Prints the design matrix.
fp | file stream pointer to output. |
B | row-major n by deg + 1 - design matrix returned by ytBSpline_designMatrix(). |
index | index vector returned by ytBSpline_designMatrix(). |
n | the number of samples. |
ndx | the number of B-splines. |
deg | degree of B-splines. |
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.
[in] | B | design matrix of size n x degree + 1, calculated by BSpline_design_matrix(). |
[in] | index | index vector of size n, calculated by BSpline_design_matrix(). |
[in] | n | number of samples |
[in] | ndx | number of B-splines. |
[in] | degree | degree of B-splines. |
[out] | BtB | matrix of size ndx x ndx used to put the results. |