SplinesModel = class SplinesModel(LinearModel) |
|
SplinesModel(knots=None, order=3, nrknots=None, min=None, max=None,
xrange=None, copy=None, **kwargs)
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. |
|
- Method resolution order:
- SplinesModel
- LinearModel
- Model
- FixedModel
- BaseModel
- builtins.object
Constructor:
- 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.
Methods defined here:
- baseDerivative( xdata, params )
- Return the derivative df/dx at each xdata (=x).
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 )
- Return the name of the parameter.
Parameters
----------
k : int
index of the parameter.
- basePartial( xdata, params, parlist=None )
- Returns the partials at the input value.
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)
- copy()
- Return a copy.
Methods inherited from LinearModel:
Methods inherited from Model:
Overloaded operators and aliases
Other methods
- addModel( model )
- appendModel( model, operation )
- assignDF1( partial, i, dpi )
- assignDF2( partial, i, dpi )
- chainLength()
- checkLimits( param, parlist )
- correctParameters( params )
- derivative( xdata, param, useNum=False )
- divideModel( model )
- domain2Unit( dvalue, kpar=None )
- getIntegralUnit()
- getLimits()
- getLinearIndex()
- getNumberOfParameters()
- getParameterName( k )
- getParameterUnit( k )
- getPrior( k )
- hasLimits( fitindex=None )
- hasPriors( isBound=True )
- isDynamic()
- isMixed()
- isNullModel()
- isolateModel( k )
- multiplyModel( model )
- nextPrior()
- numDerivative( xdata, param )
- numPartial( xdata, param )
- operate( res, pars, next )
- partial( xdata, param, useNum=False )
- partialDomain2Unit( dvalue )
- pipeModel( model )
- result( xdata, param=None )
- setLimits( lowLimits=None, highLimits=None )
- setPrior( k, prior=None, **kwargs )
- shortName()
- stayInLimits( oldpar, trypar, parlist )
- strictNumericDerivative( xdata, param )
- strictNumericPartial( xdata, params, parlist=None )
- subtractModel( model )
- testPartial( xdata, params )
- unit2Domain( uvalue, kpar=None )
Methods inherited from FixedModel:
Methods inherited from BaseModel:
|
|