Go to the source code of this file.
|
static void | bspline_eval (double *y, const double *x, int nx, int i, int degree, int deriv, const double *knots) |
|
SEXP | bspline_basis (SEXP range, SEXP x, SEXP nbasis, SEXP degree, SEXP deriv) |
|
SEXP | periodic_bspline_basis (SEXP x, SEXP nbasis, SEXP degree, SEXP period, SEXP deriv) |
|
void | bspline_basis_eval_deriv (double x, double *knots, int degree, int nbasis, int deriv, double *y) |
|
void | periodic_bspline_basis_eval_deriv (double x, double period, int degree, int nbasis, int deriv, double *y) |
|
◆ bspline_basis()
SEXP bspline_basis |
( |
SEXP |
range, |
|
|
SEXP |
x, |
|
|
SEXP |
nbasis, |
|
|
SEXP |
degree, |
|
|
SEXP |
deriv |
|
) |
| |
Definition at line 51 of file bspline.c.
54 int nb = INTEGER_VALUE(nbasis);
55 int deg = INTEGER_VALUE(degree);
56 int d = INTEGER_VALUE(deriv);
58 double dx, minx, maxx;
60 double *xdata, *ydata;
62 if (deg < 0)
err(
"must have degree > 0");
63 if (nb <= deg)
err(
"must have nbasis > degree");
64 if (d < 0)
err(
"must have deriv >= 0");
65 knots = (
double *) R_Calloc(nk,
double);
66 PROTECT(xr = AS_NUMERIC(x));
67 PROTECT(y = allocMatrix(REALSXP,nx,nb));
70 minx = REAL(range)[0];
71 maxx = REAL(range)[1];
72 if (minx >= maxx)
err(
"improper range 'rg'");
73 dx = (maxx-minx)/((
double) (nb-deg));
74 knots[0] = minx-deg*dx;
75 for (i = 1; i < nk; i++) knots[i] = knots[i-1]+dx;
76 for (i = 0; i < nb; i++) {
static void bspline_eval(double *y, const double *x, int nx, int i, int degree, int deriv, const double *knots)
◆ bspline_basis_eval_deriv()
void bspline_basis_eval_deriv |
( |
double |
x, |
|
|
double * |
knots, |
|
|
int |
degree, |
|
|
int |
nbasis, |
|
|
int |
deriv, |
|
|
double * |
y |
|
) |
| |
Definition at line 115 of file bspline.c.
117 for (
int i = 0; i < nbasis; i++) {
◆ bspline_eval()
static void bspline_eval |
( |
double * |
y, |
|
|
const double * |
x, |
|
|
int |
nx, |
|
|
int |
i, |
|
|
int |
degree, |
|
|
int |
deriv, |
|
|
const double * |
knots |
|
) |
| |
|
static |
Definition at line 9 of file bspline.c.
15 for (j = 0; j < nx; j++) y[j] = 0.0;
16 }
else if (deriv > 0) {
17 int i2 = i+1, p2 = degree-1, d2 = deriv-1;
18 double *y1 = (
double *) R_Calloc(nx,
double);
19 double *y2 = (
double *) R_Calloc(nx,
double);
23 for (j = 0; j < nx; j++) {
24 a = degree / (knots[i+degree]-knots[i]);
25 b = degree / (knots[i2+degree]-knots[i2]);
26 y[j] = a * y1[j] - b * y2[j];
28 R_Free(y1); R_Free(y2);
30 int i2 = i+1, p2 = degree-1;
32 double *y1 = (
double *) R_Calloc(nx,
double);
33 double *y2 = (
double *) R_Calloc(nx,
double);
37 for (j = 0; j < nx; j++) {
38 a = (x[j]-knots[i]) / (knots[i+degree]-knots[i]);
39 b = (knots[i2+degree]-x[j]) / (knots[i2+degree]-knots[i2]);
40 y[j] = a * y1[j] + b * y2[j];
42 R_Free(y1); R_Free(y2);
43 }
else if (degree == 0) {
44 for (j = 0; j < nx; j++)
45 y[j] = (
double) ((knots[i] <= x[j]) && (x[j] < knots[i2]));
◆ periodic_bspline_basis()
SEXP periodic_bspline_basis |
( |
SEXP |
x, |
|
|
SEXP |
nbasis, |
|
|
SEXP |
degree, |
|
|
SEXP |
period, |
|
|
SEXP |
deriv |
|
) |
| |
Definition at line 85 of file bspline.c.
90 int nb = INTEGER_VALUE(nbasis);
91 int deg = INTEGER_VALUE(degree);
92 int d = INTEGER_VALUE(deriv);
93 double pd = NUMERIC_VALUE(period);
95 double *xrd, *ydata, *val;
96 PROTECT(xr = AS_NUMERIC(x));
98 PROTECT(y = allocMatrix(REALSXP,nx,nb));
100 val = (
double *) R_alloc(nb,
sizeof(
double));
101 for (j = 0; j < nx; j++) {
103 for (k = 0; k < nb; k++) ydata[j+nx*k] = val[k];
void periodic_bspline_basis_eval_deriv(double x, double period, int degree, int nbasis, int deriv, double *y)
◆ periodic_bspline_basis_eval_deriv()
void periodic_bspline_basis_eval_deriv |
( |
double |
x, |
|
|
double |
period, |
|
|
int |
degree, |
|
|
int |
nbasis, |
|
|
int |
deriv, |
|
|
double * |
y |
|
) |
| |
Definition at line 122 of file bspline.c.
125 int nknots = nbasis+2*degree+1;
126 int shift = (degree-1)/2;
127 double *knots = NULL, *yy = NULL;
131 if (period <= 0.0)
err(
"must have period > 0");
132 if (nbasis <= 0)
err(
"must have nbasis > 0");
133 if (degree < 0)
err(
"must have degree >= 0");
134 if (nbasis < degree)
err(
"must have nbasis >= degree");
135 if (deriv < 0)
err(
"must have deriv >= 0");
137 knots = (
double *) R_Calloc(nknots+degree+1,
double);
138 yy = (
double *) R_Calloc(nknots,
double);
140 dx = period/((double) nbasis);
141 for (k = -degree; k <= nbasis+degree; k++) {
142 knots[degree+k] = k*dx;
145 if (x < 0.0) x += period;
146 for (k = 0; k < nknots; k++) {
149 for (k = 0; k < degree; k++) yy[k] += yy[nbasis+k];
150 for (k = 0; k < nbasis; k++) {
151 j = (shift+k)%nbasis;
154 R_Free(yy); R_Free(knots);