| class BasicSplinesModel( SplinesModel ) | [source] |
|---|
Splines model consisting of a basis of spline blobs.
The blobs have limited support. Each blob is a segment of polynomial order, between 2 knots. At the knots they are continuous (differentiable) upto order - 1. Similarly the edges of the blobs are smoothly connected to 0.
| order | support | behaviour between knots | continuity at knots |
|---|---|---|---|
| 0 | 1 | piecewise constant | not continuous at all |
| 1 | 2 | piecewise linear | lines are continuous (connected) |
| 2 | 3 | parabolic pieces | 1st derivatives are also continuous |
| 3 | 4 | cubic pieces | 2nd derivatives are also continuous |
| n>3 | n+1 | n-th order polynomials | (n-1)-th derivatives are continuous |
The function result is the sum over all spline blobs, multiplied with the parameters, the amplitudes of the spline blobs.
The support of the knots defined the domain where the function is defined. They are hard edges. Consequently the function is not continuous or differentiable at the edges. The spline blobs at the edges may be different from the ones in the middle.
From SplinesModel
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.
This model is NOT for (cubic) spline interpolation.
Examples
knots = numpy.arange( 17, dtype=float ) * 10 # make knots from 0 to 160
csm = BasicSplinesModel( knots=knots, order=2 )
print csm.getNumberOfParameters( )
18
# Make a periodic cubic splines, defined everwhere
knots = [0,3,9,10,11,17,20] # make knots from 0 to 20
csm = BasicSplinesModel( knots=knots, border=1 )
print csm.getNumberOfParameters( )
6
# or alternatively, as cubic splines, defined on [0,20]
csm = SplinesModel( nrknots=10, min=0, max=20 ) # automatic layout of knots
print csm.getNumberOfParameters( )
12
# or alternatively
npt = 21 # to include both 0 and 20.
x = numpy.arange( npt, dtype=float ) # x-values
csm = BasicSplinesModel( nrknots=10, xrange=x ) # automatic layout of knots
print csm.getNumberOfParameters( )
12
Attributes
- border : int (0)
behaviour at edges
0 hard edge
1 periodic
2 soft edge - period : float
distance between first and last knot (when border=1)
Attributes from SplinesModel
knots, order
Attributes from Model
npchain, parameters, stdevs, xUnit, yUnit
Attributes from FixedModel
npmax, fixed, parlist, mlist
Attributes from BaseModel
npbase, ndim, priors, posIndex, nonZero, tiny, deltaP, parNames
Limitations
Dont construct the knots so closely spaced, that there are no datapoints in between.
| BasicSplinesModel( knots=None, order=3, nrknots=None, min=None, max=None, xrange=None, border=0, copy=None, **kwargs ) | [source] |
|---|
Splines on a given set of knots and a given order.
The number of parameters is ( length( knots ) + order - 1 ), Except when border=1, then the model is periodic with ( nrknots - 1 ) parameters as the first and the last knot are the same.
Parameters
- knots : array_like
a array of arbitrarily positioned knots - order : int (3)
order of the spline. Default is cubic splines - nrknots : int
number of knots, equidistantly posited over xrange or [min,max] - border : [0, 1, 2]
defines what happens at the borders of the knot range.
0 : Just like de Boors b-splines.
the model is NOT defined outside the knot range.
1 : periodic, make knot[0] the same as knot[-1]
2 : easy borders. the model is slightly extensable. - min : float
minimum of the knot range - max : float
maximum of the knot range - xrange : array_like
range of the xdata - copy : BasicSplinesModel
model to be copied. - fixed : None or dictionary of {int:float|Model}
int index of parameter to fix permanently.
float|Model values for the fixed parameters.
Attribute fixed can only be set in the constructor.
See: FixedModel
Raises
- ValueError : At least either (
knots) or (nrknots,min,max) or
(nrknots,xrange) must be provided to define a valid model. - ValueError : when border = 1 and nrknots < order + 2, there are not enough
independent knots
Notes
The BasicSplinesModel is only strictly valid inside the domain defined by the
minmax of knots. It deteriorates fastly going outside the domain.
Except when border=1, then the model is periodic, defined everywhere
| copy( ) | [source] |
|---|
| makeBaseBasis( ) | [source] |
|---|
Return
- basis : 3-d array-like
parameters to the polynomials that make up the spline blobs
| makeDist( knotix ) | [source] |
|---|
| makePeriodicBasis( ) | [source] |
|---|
Return
- basis : 3-d array-like
parameters to the polynomials that make up the spline blobs
| normalizeBasis( basis ) | [source] |
|---|
Parameters
- basis : array_like
parameters to the polynomials that make up the spline blobs
| findParameters( knotix, dist, kpar=0 ) | [source] |
|---|
Parameters
- knotix : int array
knot indices involved in this spline blob - dist : array_like
distances between knots - kpar : int
index of parameter for which the spline-blob is constructed
Returns
- par : 2-d array
sets of poly parameters.
| baseResult( xdata, params ) | [source] |
|---|
Parameters
- xdata : array_like
value at which to calculate the partials - params : array_like
parameters to the model (ignored in LinearModels)
| basePartial( xdata, params, parlist=None ) | [source] |
|---|
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)
| makeKnotIndices( xdata ) | [source] |
|---|
Parameters
- xdata : array_like
values at which to calculate the indices
| basicBlob( xdata, basis, x2k, poly ) | [source] |
|---|
Parameters
- xdata : array_like
value at which to calculate the spline - basis : array_like
splineParameters - x2k : int_array
pointing to the knot preceeding each xdata point - poly : PolynomialModel
model to calculate the splines
| baseDerivative( xdata, params ) | [source] |
|---|
Parameters
- xdata : array_like
value at which to calculate the partials - params : array_like
parameters to the model
| baseName( ) | [source] |
|---|
Returns a string representation of the model.
| baseParameterUnit( k ) | [source] |
|---|
Parameters
- k : int
index of the parameter.
| Methods inherited from SplinesModel |
|---|
| 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 |
|---|