class DecisionTreeModel( Modifiable,Dynamic,LinearModel ) | Source |
---|
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 ) |
---|
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
copy( ) |
---|
setSplitOrMask( itype, split ) |
---|
isLeaf( ) |
---|
partitionList( xdata, plist ) |
---|
Paramaters
- xdata : array-like
the xdata - plist : array of ints
indices in xdata
Return
- pl1, pl2 : 2 lists
together containing all indices in plist
baseResult( xdata, params ) |
---|
Parameters
- xdata : array_like
values at which to calculate the result - params : array_like
values for the parameters.
recursiveResult( xdata, params, kpar, plist, res ) |
---|
basePartial( xdata, params, parlist=None ) |
---|
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 ) |
---|
sortXdata( xdata ) |
---|
Parameters
- xdata : array_like
values at which to calculate the partials
recursiveOrder( xdata, plist ) |
---|
baseDerivative( xdata, params ) |
---|
Parameters
- xdata : array_like
values at which to calculate the result - params : array_like
values for the parameters.
baseName( ) |
---|
fullName( ids=False ) |
---|
Parameters
- ids : bool
if True give the pointers of the links too.
recursiveName( name, indent, kpar, ids=False ) |
---|
baseParameterUnit( k ) |
---|
Parameters
- k : int
parameter number.
walk( ) |
---|
Found this piece of code on the internet. Fairly obscure.
encode( ) |
---|
decode( code, kdim, splim, kbr ) |
---|
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)
findLeaf( kleaf ) |
---|
Parameter
- kleaf : int
index of the leaf to be found
findBranch( kbranch ) |
---|
Parameter
- kbranch : int
index of the branch to be found
check( ) |
---|
Parameter
- kbranch : int
index of the branch to be found
findRoot( ) |
---|
count( ) |
---|
countLeaf( ) |
---|
countBranch( ) |
---|
grow( offset=0, rng=None, location=0, split=0.5, kdim=0 ) |
---|
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
- bool : succes
shrink( offset=0, rng=None, location=0 ) |
---|
Parameters
- offset : int
location where the new params should be inserted
Return
- bool : succes
vary( rng=None, location=0, split=0.5, kdim=0 ) |
---|
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
- bool : succes
Methods inherited from Modifiable, |
---|
Methods inherited from Dynamic, |
---|
- 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 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 )
- 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 |
---|