A DecisionTree Model (DTM) is mostly defined on multiple input dimensions (axes).
It splits the data in 2 parts, according low and high values on a certain input axis.
The splitting can continue along other axes.
The axes can contain float values, categorials (int) or booleans.
The float axes can have Nans when data are unkown.
Each category set one bit in an integer. The unknown category is a category
by itself.
Booleans that contain unknowns should be coded as categorial.
f( x:p ) = DTM
|-> left => DTM (or None)
|-> rite => DTM (or None)
|-> dimension
|-> split or mask
The tree is searched left to right.
The parameters are all initialized at 0.0
Examples
dtm = DecisionTreeModel( )
print( dtm )
DecisionTree: with 0 components and 1 parameters
Attributes
- left : None or DTM
a None the tree stops otherwise there is a new split.
- rite : None or DTM
a None the tree stops otherwise there is a new split.
- dimension : int
split according to data values on this axes
- itype : char. Either 'f' (float), 'i' (integer), or 'b' (boolean)
characterizes the input dimension as float, integer or boolean
- split : float between 0 and 1 (for float dimension)
to the left normalized values < split; to the rite normvalues > split.
Unknown values (NaNs to to the smallest faction).
- nsplit : int
number of calls to random.rand() to be averaged. Prior on "split"
- mask : float between 0 and 1 (for float dimension)
to the left normalized values < split; to the rite normvalues > split.
Unknown values (NaNs to to the smallest faction.
Attributes from Modifiable
modifiable
Attributes from Dynamic
dynamic
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
|
DecisionTreeModel( ndim=1, depth=0, split=0.5, kdim=0, itypes=[0], modifiable=True,
dynamic=True, code=None, growPrior=None, copy=None, **kwargs )
| [source] |
|---|
DecisionTree model.
The DTM standardly has a UniformPrior for all parameters, with limits [0,1]
Parameters
- ndim : int
number of input dimensions
- depth : int
depth of the tree
- kdim : None or list of ints
input channel to be splitted.
- itypes : [list of] int
indicating the type of input: 0 for float, 1 for boolean, >1 for categorial
The last number is repeated for remaining inputs
- split : None or float or list of floats
fraction (0<s<1) of the input kdim that falls on either side.
- growPrior : None or Prior
Governing the growth
- modifiable : bool (True)
Will the model modify dimension and/or split/mask
- dynamic : bool (True)
Will the model grow/shrink
For internal use only
Return true if self is a leaf
Partition the xdata in plist over 2 new lists according to the DTM-branch.
Paramaters
- xdata : array-like
the xdata
- plist : array of ints
indices in xdata
Return
- pl1, pl2 : 2 lists
together containing all indices in plist
Returns the result of the model function.
Parameters
- xdata : array_like
values at which to calculate the result
- params : array_like
values for the parameters.
|
recursiveResult( xdata, params, kpar, plist, res )
| [source] |
|---|
For internal use only
|
basePartial( xdata, params, parlist=None )
| [source] |
|---|
Returns the partials at the input value.
Parameters
- xdata : array_like
values at which to calculate the partials
- params : array_like
values for the parameters.
- parlist : array_like
list of indices active parameters (or None for all)
|
recursivePartial( xdata, kpar, plist, part )
| [source] |
|---|
For internal use only
Reorder the xdata according to the parameter ordering
Parameters
- xdata : array_like
values at which to calculate the partials
For internal use only
|
baseDerivative( xdata, params )
| [source] |
|---|
Return the derivative df/dx at each xdata (=x).
Parameters
- xdata : array_like
values at which to calculate the result
- params : array_like
values for the parameters.
Returns a string representation of the model.
Returns a string representation of the model.
Parameters
- ids : bool
if True give the pointers of the links too.
|
recursiveName( name, indent, kpar, ids=False )
| [source] |
|---|
For internal use only
Return the unit of the indicated parameter.
Parameters
- k : int
parameter number.
Iterate tree in pre-order depth-first search order
Found this piece of code on the internet. Fairly obscure.
Make a code tuple to be used by the constructor to resurrect the DTM
The tuple consists of
code : list of (list or 1 or 2), encoding the structure of DTM
dims : list of dimensions at the branches
splim : list of split/mask values at the branches
|
decode( code, kdim, splim, kbr )
| [source] |
|---|
Resurrect the DTM from the code generated by encode().
For internal use in the Constructor.
Parameters
- code : list
of (list or 1 or 2), encoding the structure of DTM
- dims : list
of dimensions at the branches
- splim : list
of split/mask values at the branches
- kbr : int
counter (start at 0)
Find a leaf in the tree, returning the leaf.
Parameter
- kleaf : int
index of the leaf to be found
Find a branch in the tree, returning the branch.
Parameter
- kbranch : int
index of the branch to be found
Find a branch in the tree, returning the branch.
Parameter
- kbranch : int
index of the branch to be found
Return the root of the tree.
Return number of leafs and branches.
Return number of leafs.
Return number of leafs.
|
grow( offset=0, rng=None, location=0, split=0.5, kdim=0 )
| [source] |
|---|
Increase the the number of components by 1 (if allowed by maxComp)
Parameters
- offset : int
offset in the parameter list (pertaining to earlier models in the chain)
- rng : Random Number Generator
to obtain random values for items below.
- location : int
location where the new dtm-leaf should be inserted
- kdim : int (<self.ndim)
dimension to split
- split : float (0<split<1)
relative cut on this dimension
Return
|
shrink( offset=0, rng=None, location=0 )
| [source] |
|---|
Decrease the the number of componenets by 1 (if allowed by minComp)
Remove an arbitrary item.
Parameters
- offset : int
location where the new params should be inserted
Return
|
vary( rng=None, location=0, split=0.5, kdim=0 )
| [source] |
|---|
Vary the model structure by changing kdim and/or split at location
Parameters
- rng : Random Number Generator
to obtain random values for items below.
- location : int
location where the dtm-branch should be changed
- kdim : int (<self.ndim)
dimension to split
- split : float (0<split<1)
relative cut on this dimension
Return
- isDynamic( )
- setGrowPrior( growPrior=None, min=1, max=None, name="Comp" )
- setDynamicAttribute( name, value )
- alterParameterNames( dnp )
- alterParameterSize( dnp, offset, location=None, value=0 )
- alterParameters( param, location, dnp, offset, value=None )
- alterFitindex( findex, location, dnp, offset )
- shuffle( param, offset, np, rng )
|
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 )
- 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 )