Skip to content

Commit

Permalink
version 2.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
sgsokol authored and cran-robot committed Jul 3, 2024
1 parent 44da7f0 commit 7327914
Show file tree
Hide file tree
Showing 13 changed files with 172 additions and 45 deletions.
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: bspline
Type: Package
Title: B-Spline Interpolation and Regression
Version: 2.2
Version: 2.2.2
Author: Serguei Sokol <sokol@insa-toulouse.fr>
Maintainer: Serguei Sokol <sokol@insa-toulouse.fr>
Description: Build and use B-splines for interpolation and regression.
Expand All @@ -23,10 +23,10 @@ License: GPL-2
Encoding: UTF-8
Imports: Rcpp (>= 1.0.7), nlsic (>= 1.0.2), arrApply
LinkingTo: Rcpp, RcppArmadillo
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Suggests: RUnit
Copyright: INRAE/INSA/CNRS
NeedsCompilation: yes
Packaged: 2023-05-26 14:20:22 UTC; sokol
Packaged: 2024-07-02 13:38:22 UTC; sokol
Repository: CRAN
Date/Publication: 2023-05-26 15:00:02 UTC
Date/Publication: 2024-07-02 15:00:02 UTC
23 changes: 12 additions & 11 deletions MD5
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
73d3d506a8fe0a83d4e89a953c7898d0 *DESCRIPTION
e0801632c53847831d661287c17718a6 *NAMESPACE
dd97189b50df668bfe8de4552fb71012 *NEWS.md
449a72dce2f37883177f5c1296aa563d *R/RcppExports.R
57dc0e4fa21165266d1b84113ef47c46 *R/bspline.R
5c40aeebb22d9fe81c57f573b4af93a5 *DESCRIPTION
156b2d6d9e93c6c978881aa74afc222f *NAMESPACE
091979c863ee3c5dfe54684ac1385b73 *NEWS.md
d17c0778007c8210b43e23ddf1b760d4 *R/RcppExports.R
4cb76b35000c7fcd3f105c7bd0bde0d2 *R/bspline.R
f37de71584e33ed7935fe5fed83ec76a *cleanup
9004dfabb65b2f8940389f2145f0f4a7 *inst/include/bspline.h
0fdd483e16435aeafe2dcfec1e8e4caf *inst/unitTests/runit.bspline.R
bf8b683720e20943eb49ae2646d01b36 *man/bcurve.Rd
d7d46e5f9446e055a7db6ffb5a53a365 *man/bsc.Rd
1020ba06fb042025f5fd8ef054c4608e *man/bsp.Rd
24e2a0558672238bdf74612db41612fd *man/bspline.Rd
87eb91268888216a835fe33ba4447405 *inst/unitTests/runit.bspline.R
72d6c465dcb7c1fe71c31d56ae39d991 *man/bcurve.Rd
7c8d9a8be9f75fd422e435c02da2bb89 *man/bsc.Rd
1cf1df33daab2b31a45deb7793dbcc05 *man/bsp.Rd
0a50d2bde02036b30855db8b71eeb128 *man/bspline.Rd
d1bdf4adfa4bd5d2d74c87fd28c963f1 *man/bsppar.Rd
8424d1dc2beaafd4af6cb6d1a4c0f60d *man/dbsp.Rd
9485d720901f71075f53701dff2f0d0d *man/diffn.Rd
Expand All @@ -20,8 +20,9 @@ f0206401427d28b13c556021e96f871a *man/iknots.Rd
bb07ce30afc1b68249019d6a49af4ac5 *man/jacw.Rd
f3a5b6cac003db82e92711539a3f7e1a *man/par2bsp.Rd
671f005a4d5c9c680f0a7f4d6903ce60 *man/parr.Rd
376200d5a1f9fe3e3c1355b96c77472b *man/pbsc.Rd
e46c13d9b674bccbe7e71a10adfa43ca *man/smbsp.Rd
3996e7c16bfb96fad295ee425815cb4d *src/Makevars
36a5574ff46e7959e9ba2fac4eea5f35 *src/RcppExports.cpp
02e070596a276755547f970a015bdde5 *src/bspline.cpp
8ff97d80124f024b4e961a5d19c4f5e5 *src/bspline.cpp
34568066174ae79807c62bad454cb79f *tests/RUnit.R
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export(ipk)
export(jacw)
export(par2bsp)
export(parr)
export(pbsc)
export(smbsp)
importFrom(Rcpp,evalCpp)
importFrom(arrApply,arrApply)
Expand Down
14 changes: 14 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
## v2.2.2 2024-07-02

- fixed typo in example of `pbsc()`
- fixed syntax error in manul for `bsc()` and `bsp()`
- fixed missing variable in test of example for `pbsc()`
- fixed missing export for `pbsc()`

## v2.2.1 2023-05-30

- fixed typo in rgl example of `bcurve()`
- fixed NEWS mention of `parr()` for v2.2.
- added `pbsc()`

## v2.2 2023-05-26

- added `bcurve()` for building nD curves from a set of control points
- added `parr()` polynomial formulation of B-splines

## v2.1 2022-09-26

Expand Down
27 changes: 26 additions & 1 deletion R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ ipk <- function(x, xk) {
#' in points where x=xk, the derivative is not defined.\cr
#' For n==1, Jacobian is discontinuous in such points so for
#' these points we take the derivative from the right.
#' @seealso {splines::bs()}, {splines2::bSpline()}
#' @seealso [splines::bs()], [splines2::bSpline()]
#' @examples
#' x=seq(0, 5, length.out=101)
#' # cubic basis matrix
Expand Down Expand Up @@ -78,6 +78,31 @@ parr <- function(xk, n = 3L) {
.Call(`_bspline_parr`, xk, n)
}

#' Polynomial B-spline Calculation of Basis Matrix
#'
#' @param x Numeric,vector, abscissa points
#' @param xk Numeric vector, knots
#' @param coeffs, Numeric 3D array, polynomial coefficients such as calculated by \code{\link{parr}}
#' @return Numeric matrix, basis vectors, one per column. Row number is \code{length(x)}.
#' @details
#' Polynomials are calculated recursively by Cox-de Boor formula. However, it is not applied to
#' final values but to polynomial coefficients. Multiplication by a linear functions gives
#' a raise of polynomial degree by 1.\cr
#' Polynomial coefficients stored in the first dimension of \code{coeffs} are used as in
#' the following formula \code{p[1]*x^n + p[1]*x^(n-1) + ... + p[n+1]}. \cr
#' Resulting matrix is the same as returned by \code{bsc(x, xk, n=dim(coeffs)[1]-1)}
#' @examples
#' n=3
#' x=seq(0, 5, length.out=101)
#' xk=c(rep(0, n+1), 1:4, rep(5, n+1))
#' # cubic polynomial coefficients
#' coeffs=parr(xk)
#' # basis matrix
#' m=pbsc(x, xk, coeffs)
#' matplot(x, m, t="l")
#' stopifnot(all.equal.numeric(c(m), c(bsc(x, xk))))
#' @seealso \code{\link{bsc}}
#' @export
pbsc <- function(x, xk, coeffs) {
.Call(`_bspline_pbsc`, x, xk, coeffs)
}
Expand Down
22 changes: 11 additions & 11 deletions R/bspline.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
#' performance that's why the basis calculation is implemented in C++.
#' The rest is implemented in R but without notable impact on computing speed.
#'
#' @section bspline functions: \itemize{
#' \item{\code{bsc}:}{ basis matrix (implemented in C++)}
#' \item{\code{bsp}:}{ values of B-spline from its coefficients}
#' \item{\code{dbsp}:}{ derivative of B-spline}
#' \item{\code{par2bsp}:}{ build B-spline function from parameters }
#' \item{\code{bsppar}:}{ retrieve B-spline parameters from its function}
#' \item{\code{smbsp}:}{ build smoothing B-spline}
#' \item{\code{fitsmbsp}:}{ build smoothing B-spline with optimized knot positions}
#' \item{\code{diffn}:}{ finite differences}
#' @section bspline functions: \describe{
#' \item{"\code{bsc}:"}{ basis matrix (implemented in C++)}
#' \item{"\code{bsp}:"}{ values of B-spline from its coefficients}
#' \item{"\code{dbsp}:"}{ derivative of B-spline}
#' \item{"\code{par2bsp}:"}{ build B-spline function from parameters }
#' \item{"\code{bsppar}:"}{ retrieve B-spline parameters from its function}
#' \item{"\code{smbsp}:"}{ build smoothing B-spline}
#' \item{"\code{fitsmbsp}:"}{ build smoothing B-spline with optimized knot positions}
#' \item{"\code{diffn}:"}{ finite differences}
#' }
#'
#' @docType package
Expand All @@ -46,7 +46,7 @@ NULL
#' For x values falling outside of xk range, the B-splines values are set to 0.
#' To get a function calculating spline values at arbitrary points from \code{xk}
#' and \code{qw}, cf. \code{par2bsp()}.
#' @seealso {bsc}, {par2bsp}
#' @seealso [bsc], [par2bsp]
#' @export
bsp=function(x, xk, qw, n=3L) {
stopifnot(NROW(qw) == length(xk)-n-1L)
Expand Down Expand Up @@ -638,7 +638,7 @@ iknots=function(x, y, nki=1L, n=3L) {
#'
#' # randomly curved wire in 3D space
#'\dontrun{
#' if (requireNamespace("rgl", quite=TRUE)) {
#' if (requireNamespace("rgl", quietly=TRUE)) {
#' xyz=matrix(rnorm(24),ncol=3)
#' tp=seq(0,1,len=201)
#' curv3d=bcurve(xyz)
Expand Down
10 changes: 10 additions & 0 deletions inst/unitTests/runit.bspline.R
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,13 @@ test.bcurve.ex=function() {
#print(bcurve(xy)(0.5))
checkEqualsNumeric(c(-0.03506473, -0.1508343), bcurve(xy)(0.5), tol=1.e-6)
}
test.pbsc.ex=function() {
n=3
x=seq(0, 5, length.out=101)
xk=c(rep(0, n+1), 1:4, rep(5, n+1))
# cubic polynomial coefficients
coeffs=parr(xk, n)
# basis matrix
m=pbsc(x, xk, coeffs)
checkEqualsNumeric(c(m), c(bsc(x, xk)))
}
2 changes: 1 addition & 1 deletion man/bcurve.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/bsc.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/bsp.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 18 additions & 9 deletions man/bspline.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions man/pbsc.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 30 additions & 6 deletions src/bspline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ umat ipk(const vec& x, const vec& xk) {
//' in points where x=xk, the derivative is not defined.\cr
//' For n==1, Jacobian is discontinuous in such points so for
//' these points we take the derivative from the right.
//' @seealso {splines::bs()}, {splines2::bSpline()}
//' @seealso [splines::bs()], [splines2::bSpline()]
//' @examples
//' x=seq(0, 5, length.out=101)
//' # cubic basis matrix
Expand Down Expand Up @@ -287,16 +287,39 @@ cube parr(const vec &xk, const size_t n=3) {
res.resize(n+1, n+1, nk-n-1);
return res;
}
//' Polynomial B-spline Calculation of Basis Matrix
//'
//' @param x Numeric,vector, abscissa points
//' @param xk Numeric vector, knots
//' @param coeffs, Numeric 3D array, polynomial coefficients such as calculated by \code{\link{parr}}
//' @return Numeric matrix, basis vectors, one per column. Row number is \code{length(x)}.
//' @details
//' Polynomials are calculated recursively by Cox-de Boor formula. However, it is not applied to
//' final values but to polynomial coefficients. Multiplication by a linear functions gives
//' a raise of polynomial degree by 1.\cr
//' Polynomial coefficients stored in the first dimension of \code{coeffs} are used as in
//' the following formula \code{p[1]*x^n + p[1]*x^(n-1) + ... + p[n+1]}. \cr
//' Resulting matrix is the same as returned by \code{bsc(x, xk, n=dim(coeffs)[1]-1)}
//' @examples
//' n=3
//' x=seq(0, 5, length.out=101)
//' xk=c(rep(0, n+1), 1:4, rep(5, n+1))
//' # cubic polynomial coefficients
//' coeffs=parr(xk)
//' # basis matrix
//' m=pbsc(x, xk, coeffs)
//' matplot(x, m, t="l")
//' stopifnot(all.equal.numeric(c(m), c(bsc(x, xk))))
//' @seealso \code{\link{bsc}}
//' @export
// [[Rcpp::export]]
mat pbsc(const vec& x, const vec& xk, const cube& coeffs) {
// polynomial B-spline calculation of basis matrix
// p[0]*x^n + p[1]*x^(n-1) + ... + p[n]
size_t n=coeffs.n_rows-1;
size_t nk=coeffs.n_slices+n+1;
size_t nsp=nk-n-1;
size_t first, last;
if (nk != xk.n_elem)
stop("The length(xk)=%d must be equal to dim(coeffs)[3]+dim(coeffs)[1]=%d+%d=%d", xk.n_elem, nk-n-1, n+1, nk);
stop("pbsc: the length(xk)=%d must be equal to dim(coeffs)[3]+dim(coeffs)[1]=%d+%d=%d", xk.n_elem, nsp, n+1, nk);
mat res(x.n_elem, nsp, fill::zeros);
umat ip=ipk(x, xk);
//ip.print("ip");
Expand All @@ -305,8 +328,9 @@ mat pbsc(const vec& x, const vec& xk, const cube& coeffs) {
for (size_t isup=0; isup <= n; ++isup) {
//Rcout << "\tisup=" << isup << std::endl;
first=ip(0, isp+isup);
last=ip(1, isp+isup)-1;
if (last >= first) {
last=ip(1, isp+isup);
if (last > first) {
last -= 1;
res.col(isp).subvec(first, last) += polyval(coeffs.slice(isp).col(isup), x.subvec(first, last)-xk[isp+isup]);
//res.print("res");
}
Expand Down

0 comments on commit 7327914

Please sign in to comment.