class BSplinesModel( LinearModel ) | Source |
---|
General b-splines model of arbitrary order and with arbitrary knot settings.
It encapsulates the bspline package of John Foster and Juha Jeronen, at http://github.com/johnfoster/bspline.
B-splines have some advantages over natural splines as implemented in SplinesModel. Specificly the parameters are much more easily interpreted as the amplitudes of spline-like blobs. The disadvantage of BSplinesModel is that the x-values need to fall strictly within the range spanned by the knots.
It is a linear model.
order | behaviour between knots | continuity at knots |
---|---|---|
0 | piecewise constant | not continuous at all |
1 | piecewise linear | lines are continuous |
2 | parabolic pieces | 1st derivatives are also continuous |
3 | cubic pieces | 2nd derivatives are also continuous |
n>3 | n-th order polynomials | (n-1)th derivatives are continuous |
The user lays out a number ( << datapoints ) of knots on the x-axis at arbitrary position, generally more knots where the curvature is higher. The knots need to be monotonuously increasing in x. Alternatively one can ask this class to do the lay-out which is then equidistant in x over the user-provided range. Through these knots a splines function is obtained which best fits the datapoints. One needs at least 2 knots, one smaller and one larger than the x-values in the dataset.
Contrary to the SplinesModel here the xdata need to be strictly inside the range spanned by the knots: knots[0] <= xdata < knots[-1]
This model is NOT for (cubic) spline interpolation.
Examples
knots = numpy.arange( 17, dtype=float ) * 10 # make equidistant knots from 0 to 160
csm = BSplinesModel( knots=knots, order=2 )
print csm.getNumberOfParameters( )
18
# or alternatively
csm = BSplinesModel( nrknots=17, order=2, min=0, max=160 ) # automatic layout of knots
print csm.getNumberOfParameters( )
18
# or alternatively
npt = 161 # to include both 0 and 160.
x = numpy.arange( npt, dtype=float ) # x-values
csm = BSplinesModel( nrknots=17, order=2, xrange=x ) # automatic layout of knots
print csm.getNumberOfParameters( )
18
Attributes
- knots : array_like
a array of arbitrarily positioned knots - order : int
order of the spline. Default 3 (cubic splines) - eps : float
small number to enable inclusion of endpoints. Default 0.0.
Attributes from Model
parameters, stdevs, xUnit, yUnit, npchain
Attributes from FixedModel
npmax, fixed, parlist, mlist
Attributes from BaseModel
npbase, ndim, priors, posIndex, nonZero, tiny, deltaP, parNames
Limitations
Dont put the knots too closely so that there are no datapoints in between.
BSplinesModel( knots=None, order=3, nrknots=None, min=None, max=None, xrange=None, copy=None, fixed=None, **kwargs ) |
---|
Splines on a given set of knots and a given order.
The number of parameters is ( length( knots ) + order - 1 )
Parameters
- knots : array_like
a array of arbitrarily positioned knots - order : int
order of the spline. Default 3 (cubic splines) - nrknots : int
number of knots, equidistantly posited over xrange or [min,max] - min : float
minimum of the knot range - max : float
maximum of the knot range - xrange : array_like
range of the xdata - copy : BSplinesModel
model to be copied. - fixed : dict
If not None, raise AttributeError.
Raises
- ValueError : At least either ('knots') or ('nrnkots', 'min', 'max') or
('nrknots', 'xrange') must be provided to define a valid model. - AttributeErrr : When fixed is not None
Notes
The BSplinesModel is only strictly valid inside the domain defined by the minmax of knots. It does not exist outside that domain.
copy( ) |
---|
basePartial( xdata, params, parlist=None ) |
---|
The partials are the powers of x (input) from 0 to degree.
Parameters
- xdata : array_like
value at which to calculate the partials - params : array_like
parameters to the model (ignored in LinearModels) - parlist : array_like
list of indices active parameters (or None for all)
Raises
ValueError when xdata < knots[0] or xdata > knots[1]
baseDerivative( xdata, params ) |
---|
Parameters
- xdata : array_like
value at which to calculate the partials - params : array_like
parameters to the model
baseName( ) |
---|
Returns a string representation of the model.
baseParameterUnit( k ) |
---|
Parameters
- k : int
index of the parameter.
Methods inherited from LinearModel |
---|
Methods inherited from Model |
---|
- chainLength( )
- isNullModel( )
- isolateModel( k )
- addModel( model )
- subtractModel( model )
- multiplyModel( model )
- divideModel( model )
- pipeModel( model )
- appendModel( model, operation )
- correctParameters( params )
- result( xdata, param=None )
- operate( res, pars, next )
- derivative( xdata, param, useNum=False )
- partial( xdata, param, useNum=False )
- selectPipe( ndim, ninter, ndout )
- pipe_0( dGd, dHdG )
- pipe_1( dGd, dHdG )
- pipe_2( dGd, dHdG )
- pipe_3( dGd, dHdG )
- pipe_4( dGdx, dHdG )
- pipe_5( dGdx, dHdG )
- pipe_6( dGdx, dHdG )
- pipe_7( dGdx, dHdG )
- pipe_8( dGdx, dHdG )
- pipe_9( dGdx, dHdG )
- shortName( )
- getNumberOfParameters( )
- numDerivative( xdata, param )
- numPartial( xdata, param )
- isDynamic( )
- hasPriors( isBound=True )
- getPrior( kpar )
- setPrior( kpar, prior=None, **kwargs )
- getParameterName( kpar )
- getParameterUnit( kpar )
- getIntegralUnit( )
- setLimits( lowLimits=None, highLimits=None )
- getLimits( )
- hasLimits( fitindex=None )
- unit2Domain( uvalue, kpar=None )
- domain2Unit( dvalue, kpar=None )
- partialDomain2Unit( dvalue )
- nextPrior( )
- isMixed( )
- getLinearIndex( )
- testPartial( xdata, params, silent=True )
- strictNumericPartial( xdata, params, parlist=None )
- assignDF1( partial, i, dpi )
- assignDF2( partial, i, dpi )
- strictNumericDerivative( xdata, param )
Methods inherited from FixedModel |
---|
Methods inherited from BaseModel |
---|