DecisionTreeModel = class DecisionTreeModel(Modifiable, Dynamic, LinearModel) |
|
DecisionTreeModel(ndim=1, depth=0, split=0.5, kdim=0, itypes=[0],
modifiable=True, dynamic=True, code=None, growPrior=None, copy=None,
**kwargs)
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)
ite => 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 |
|
- Method resolution order:
- DecisionTreeModel
- Modifiable
- Dynamic
- LinearModel
- Model
- FixedModel
- BaseModel
- builtins.object
Constructor:
- 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
Methods defined here:
- baseDerivative( xdata, params )
- 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.
- baseName()
- Returns a string representation of the model.
- baseParameterUnit( k )
- Return the unit of the indicated parameter.
Parameters
---------
k : int
parameter number.
- basePartial( xdata, params, parlist=None )
- 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)
- baseResult( xdata, params )
- 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.
- check()
- Find a branch in the tree, returning the branch.
Parameter
---------
kbranch : int
index of the branch to be found
- copy()
- Copy method.
- count()
- Return number of leafs and branches.
- countBranch()
- Return number of leafs.
- countLeaf()
- Return number of leafs.
- decode( code, kdim, splim, kbr )
- 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)
- encode()
- 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
- findBranch( kbranch )
- Find a branch in the tree, returning the branch.
Parameter
---------
kbranch : int
index of the branch to be found
- findLeaf( kleaf )
- Find a leaf in the tree, returning the leaf.
Parameter
---------
kleaf : int
index of the leaf to be found
- findRoot()
- Return the root of the tree.
- fullName( ids=False )
- Returns a string representation of the model.
Parameters
----------
ids : bool
if True give the pointers of the links too.
- grow( offset=0, rng=None, location=0, split=0.5, kdim=0)
- 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
------
bool : succes
- isLeaf()
- Return true if is a leaf
- partitionList( xdata, plist )
- 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
- recursiveName( name, indent, kpar, ids=False )
- For internal use only
- recursiveOrder( xdata, plist )
- For internal use only
- recursivePartial( xdata, kpar, plist, part )
- For internal use only
- recursiveResult( xdata, params, kpar, plist, res )
- For internal use only
- setSplitOrMask( itype, split )
- For internal use only
- shrink( offset=0, rng=None, location=0)
- 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
------
bool : succes
- sortXdata( xdata )
- Reorder the xdata according to the parameter ordering
Parameters
----------
xdata : array_like
values at which to calculate the partials
- vary( rng=None, location=0, split=0.5, kdim=0)
- 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
------
bool : succes
- walk()
- Iterate tree in pre-order depth-first search order
Found this piece of code on the internet. Fairly obscure.
Methods inherited from Modifiable:
Methods inherited from Dynamic:
- alterFitindex( findex, location, dnp, offset )
- alterParameterNames( dnp )
- alterParameterSize( dnp, offset, location=None, value=0)
- alterParameters( param, location, dnp, offset, value=None )
- isDynamic()
- setDynamicAttribute( name, value )
- setGrowPrior( growPrior=None, min=1, max=None, name='Comp')
- shuffle( param, offset, np, rng )
Methods inherited from Model:
Overloaded operators and aliases
Other methods
- addModel( model )
- appendModel( model, operation )
- assignDF1( partial, i, dpi )
- assignDF2( partial, i, dpi )
- chainLength()
- 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 )
- 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 )
- 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)
- result( xdata, param=None )
- selectPipe( ndim, ninter, ndout )
- setLimits( lowLimits=None, highLimits=None )
- setPrior( k, prior=None, **kwargs )
- shortName()
- strictNumericDerivative( xdata, param )
- strictNumericPartial( xdata, params, parlist=None )
- subtractModel( model )
- testPartial( xdata, params, silent=True )
- unit2Domain( uvalue, kpar=None )
Methods inherited from FixedModel:
Methods inherited from BaseModel:
|
|