class SplinesModel( LinearModel ) | Source |
---|
General splines model of arbitrary order and with arbitrary knot settings. 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 (connected) |
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 also 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.
If the end knots are put in between the x-values in the dataset, a kind of extrapoling spline is obtained. It still works more or less. Dont push it.
This model is NOT for (cubic) spline interpolation.
Examples
knots = numpy.arange( 17, dtype=float ) * 10 # make equidistant knots from 0 to 160
csm = SplinesModel( knots=knots, order=2 )
print csm.getNumberOfParameters( )
18
# or alternatively
csm = SplinesModel( 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 = SplinesModel( nrknots=17, order=2, xrange=x ) # automatic layout of knots
print csm.getNumberOfParameters( )
18
Attributes
- knots : array_like
positions of the spline knots - order : int
order of the spline. default: 3
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.
SplinesModel( knots=None, order=3, nrknots=None, min=None, max=None, xrange=None, copy=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 : SplinesModel
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.
Notes
The SplinesModel is only strictly valid inside the domain defined by the minmax of knots. It deteriorates fastly going outside the 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)
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 |
---|