Title: | Orthogonal B-Spline Basis Functions |
---|---|
Description: | Represents the basis functions for B-splines in a simple matrix formulation that facilitates, taking integrals, derivatives, and making orthogonal the basis functions. |
Authors: | Andrew Redd |
Maintainer: | Andrew Redd <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.1.7 |
Built: | 2025-03-21 04:33:01 UTC |
Source: | https://github.com/halpo/obsplines |
This package provides functions for manipulation of spline basis functions. A matrix representation for the basis functions is at the center of the functions. The matrix representation simplifies the process of orthogonalization as well as differentiation and integration.
Andrew Redd Maintainer: Andrew Redd [email protected]
Methods for function evaluate
.
Evaluates a SplineBasis
object for the spline basis curves at points x
. See SplineBasis
This function is for convenience of specifying knots for B-splines. Since the user usually only want to specify the interval that they are interested in the end knots are usually duplicated. This function interprets the first and last knots as the end points and duplicates them.
expand.knots(interior, order = 4)
expand.knots(interior, order = 4)
interior |
The knots including all interior and endpoint knots |
order |
the order of the splines that the knots are to be used with. Defaults to 4, being cubic splines |
A vector of knots with the order specified as an attribute
Andrew Redd
SplineBasis
, ~~~
(knots<-expand.knots(1:10)) plot(OBasis(knots))
(knots<-expand.knots(1:10)) plot(OBasis(knots))
Estimates the control vector for a spline fit by penalized least squares. The penalty being the penalty parameter times the functional inner product of the second derivative of the spline curve.
fitLS(object, x, y, penalty = 0)
fitLS(object, x, y, penalty = 0)
object |
The |
x |
predictor variable. |
y |
response variable. |
penalty |
The penalty multiplier. |
For numeric vector y, and x, and a set of basis functions, represented in object
, defined on the knots .
The likelihood is defined by
The function estimates .
a vector of the control points.
knots<-c(0,0,0,0:5,5,5,5) base<-SplineBasis(knots) x<-seq(0,5,by=.5) y<-exp(x)+rnorm(length(x),sd=5) fitLS(base,x,y)
knots<-c(0,0,0,0:5,5,5,5) base<-SplineBasis(knots) x<-seq(0,5,by=.5) y<-exp(x)+rnorm(length(x),sd=5) fitLS(base,x,y)
Function for computing the Gram matrix of a spline basis.
GramMatrix(object)
GramMatrix(object)
object |
a SplineBasis object |
Compute the Gram Matrix. If object
denotes the basis functions then the Gram Matrix is,
a matrix as defined above.
Functions to generate a Hankel matrix.
Hankel(x, nrow = length(x)%/%2, ncol = length(x)%/%2)
Hankel(x, nrow = length(x)%/%2, ncol = length(x)%/%2)
x |
numeric vector to specify the entries of the matrix. Should have an even number of entries. |
nrow |
integer, must be at most length(x) |
ncol |
integer, must be at most length(x) |
Computes a Hankel matrix. If we denote the vector the Hankel matrix is defined and formed as
a matrix as defined above.
Hankel(1:6)
Hankel(1:6)
Methods for function integrate
. integrate
integrates generic objects for which an integral is defined.
Returns a new SplineBasis
object for the integral of the basis functions. See SplineBasis
Performs the matrix power operation.
MatrixPower(A, n)
MatrixPower(A, n)
A |
A square matrix. |
n |
An integer telling the exponent. |
Only well defined for integers the matrix power operation is a convenience function to multiply a matrix, A
, with itself n
times.
A matrix of the same dimension as A
.
A<-rbind(0,cbind(diag(1:5),0)) #a nilpotent matrix A MatrixPower(A,3) MatrixPower(A,5) MatrixPower(A,6) #Gets to a zero matrix
A<-rbind(0,cbind(diag(1:5),0)) #a nilpotent matrix A MatrixPower(A,3) MatrixPower(A,5) MatrixPower(A,6) #Gets to a zero matrix
A generic function for orthogonalizing an object and returning the orthogonal object
Orthogonalize the spline basis functions. See SplineBasis
Specific function for orthogonalizing the functions in a SplineBasis
object.
OrthogonalizeBasis(object, ...)
OrthogonalizeBasis(object, ...)
object |
A |
... |
ignored |
An OrthogonalSplineBasis
object.
OrthogonalSplineBasis
, SplineBasis
,orthogonalize
Provides the functional outer product of second derivatives of a set of basis functions in a SplineBasis
object.
It a convenient form for forming a penalty on curve smoothness when fitting a spline curve.
OuterProdSecondDerivative(basis)
OuterProdSecondDerivative(basis)
basis |
A |
A square matrix of order nrow(basis)
.
SplineBasis
Objects.The function to create SplineBasis
and OrthogonalSplineBasis
Objects
SplineBasis(knots, order=4, keep.duplicates=FALSE) OrthogonalSplineBasis(knots, ...) OBasis(...)
SplineBasis(knots, order=4, keep.duplicates=FALSE) OrthogonalSplineBasis(knots, ...) OBasis(...)
knots |
The full set of knots used to define the basis functions. |
order |
Order of the spline fit.(degree= order-1) |
keep.duplicates |
Should duplicate interior knots that could cause computation problem be kept or removed. Defaults to false, which removes duplicate knots with a warning if duplicate interior knots are found. |
... |
Other arguments either ignored or passed onto other functions. |
SplineBasis
produces an object representing the basis functions used in spline fitting. Provides a compact easily evaluated representation of the functions. Produces a class of object SplineBasis
.
OrthogonalSplineBasis
is a shortcut to obtain a set of orthogonalized basis functions from the knots. OBasis
is an alias for OrthogonalSplineBasis
. Both provide an object of class OrthogonalSplineBasis
. The class OrthogonalSplineBasis
inherits directly from SplineBasis
meaning all functions that apply to SplineBasis
functions also apply to the orthogonalized version.
Object of class SplineBasis
or OrthogonalSplineBasis
General matrix representations for B-splines Kaihuai, Qin, The Visual Computer 2000 16:177–186
SplineBasis
, spline
, orthogonalsplinebasis-package
knots<-c(0,0,0,0:10,10,10,10) plot(SplineBasis(knots)) obase<-OBasis(knots) plot(obase) dim(obase)[2] #number of functions evaluate(obase, 1:10-.5)
knots<-c(0,0,0,0:10,10,10,10) plot(SplineBasis(knots)) obase<-OBasis(knots) plot(obase) dim(obase)[2] #number of functions evaluate(obase, 1:10-.5)
SplineBasis
and OrthogonalSplineBasis
Contains the matrix representation for spline basis functions. The OrthogonalSplineBasis
class has the basis functions orthogonalized.
Objects can be created by calls of the form SplineBasis(knots, order)
or to generate orthogonal spline basis functions directly OrthogonalSplineBasis(knots, order)
or the short version OBasis(knots,order)
.
transformation
:Object of class "matrix"
Only applicable on OrthogonalSplineBasis
class, shows the transformation matrix use to get from regular basis functions to orthogonal basis functions.
knots
:Object of class "numeric"
order
:Object of class "integer"
Matrices
:Object of class "array"
signature(expr = "SplineBasis")
: Computes the derivative of the basis functions. Returns an object of class SplineBasis
.
signature(x = "SplineBasis")
: gives the dim as the order and number of basis functions. Returns numeric of length 2.
signature(object = "SplineBasis", x = "numeric")
: Evaluates the basis functions and the points provided in x. Returns a matrix with length(x)
rows and dim(object)[2]
columns.
signature(object = "SplineBasis")
: computes the integral of the basis functions defined by where
is the first knot. Returns an object of class
SplineBasis
.
signature(object = "SplineBasis")
: Takes in a SplineBasis
object, computes the orthogonalization transformation and returns an object of class OrthogonalSplineBasis
.
signature(x = "SplineBasis", y = "missing")
: Takes an object of class SplineBasis
and plots the basis functions for the domain defined by the knots in object.
signature(x = "SplineBasis", y = "vector")
: Interprets y as a vector of coefficients and plots the resulting curve.
signature(x = "SplineBasis", y = "matrix")
: Interprets y as a matrix of coefficients and plots the resulting curves.
General matrix representations for B-splines Kaihuai Qin, The Visual Computer 2000 16:177–186
showClass("SplineBasis") knots<-c(0,0,0,0:5,5,5,5) (base <-SplineBasis(knots)) (obase<-OBasis(knots)) plot(base) plot(obase)
showClass("SplineBasis") knots<-c(0,0,0,0:5,5,5,5) (base <-SplineBasis(knots)) (obase<-OBasis(knots)) plot(base) plot(obase)