shark::CARTree< LabelType > Class Template Reference

Classification and Regression Tree. More...

#include <shark/Models/Trees/CARTree.h>

+ Inheritance diagram for shark::CARTree< LabelType >:

Classes

struct  Node
 

Public Types

typedef base_type::BatchInputType BatchInputType
 
typedef base_type::BatchOutputType BatchOutputType
 
typedef std::vector< NodeTreeType
 
- Public Types inherited from shark::AbstractModel< RealVector, LabelType >
enum  Feature
 
typedef RealVector InputType
 Defines the input type of the model. More...
 
typedef LabelType OutputType
 Defines the output type of the model. More...
 
typedef AbstractModel< RealVector, LabelType, RealVector > ModelBaseType
 Defines the BaseType used by the model (this type). Useful for creating derived models. More...
 
typedef Batch< InputType >::type BatchInputType
 defines the batch type of the input type. More...
 
typedef Batch< OutputType >::type BatchOutputType
 defines the batch type of the output type More...
 
typedef TypedFlags< FeatureFeatures
 
typedef TypedFeatureNotAvailableException< FeatureFeatureNotAvailableException
 
- Public Types inherited from shark::IParameterizable< RealVector >
typedef RealVector ParameterVectorType
 

Public Member Functions

 CARTree (std::size_t inputDimension=0)
 Constructor. More...
 
std::string name () const
 From INameable: return the class name. More...
 
boost::shared_ptr< StatecreateState () const
 Creates an internal state of the model. More...
 
void eval (BatchInputType const &patterns, BatchOutputType &outputs) const
 Evaluate the Tree on a batch of patterns. More...
 
void eval (BatchInputType const &patterns, BatchOutputType &outputs, State &state) const
 Standard interface for evaluating the response of the model to a batch of patterns. More...
 
void eval (RealVector const &pattern, LabelType &output)
 Evaluate the Tree on a single pattern. More...
 
std::size_t numberOfParameters () const
 The model does not have any parameters. More...
 
RealVector parameterVector () const
 The model does not have any parameters. More...
 
void setParameterVector (RealVector const &param)
 The model does not have any parameters. More...
 
void read (InArchive &archive)
 from ISerializable, reads a model from an archive More...
 
void write (OutArchive &archive) const
 from ISerializable, writes a model to an archive More...
 
UIntVector countAttributes () const
 
Shape inputShape () const
 Return input dimension. More...
 
Shape outputShape () const
 Returns the shape of the output. More...
 
std::size_t numberOfNodes () const
 
NodegetNode (std::size_t nodeId)
 Returns the node with id nodeId. More...
 
Node const & getNode (std::size_t nodeId) const
 Returns the node with id nodeId. More...
 
LabelType const & getLabel (std::size_t nodeId) const
 
NodecreateRoot ()
 Creates and returns an untyped root node (neither internal, nor leaf node) More...
 
NodetransformInternalNode (std::size_t nodeId, std::size_t attributeIndex, double attributeValue)
 Transforms an untyped node (no child, no internal node) into an internal node. More...
 
NodetransformLeafNode (std::size_t nodeId, LabelType const &label)
 Transforms a node (no leaf) into a leaf node and inserts the appropriate label. More...
 
void reorderBFS ()
 Reorders a tree into a breath-first-ordering. More...
 
- Public Member Functions inherited from shark::AbstractModel< RealVector, LabelType >
 AbstractModel ()
 
virtual ~AbstractModel ()
 
const Featuresfeatures () const
 
virtual void updateFeatures ()
 
bool hasFirstParameterDerivative () const
 Returns true when the first parameter derivative is implemented. More...
 
bool hasFirstInputDerivative () const
 Returns true when the first input derivative is implemented. More...
 
virtual void eval (InputType const &pattern, OutputType &output) const
 Standard interface for evaluating the response of the model to a single pattern. More...
 
Data< OutputTypeoperator() (Data< InputType > const &patterns) const
 Model evaluation as an operator for a whole dataset. This is a convenience function. More...
 
OutputType operator() (InputType const &pattern) const
 Model evaluation as an operator for a single pattern. This is a convenience function. More...
 
BatchOutputType operator() (BatchInputType const &patterns) const
 Model evaluation as an operator for a single pattern. This is a convenience function. More...
 
virtual void weightedParameterDerivative (BatchInputType const &pattern, BatchOutputType const &outputs, BatchOutputType const &coefficients, State const &state, RealVector &derivative) const
 calculates the weighted sum of derivatives w.r.t the parameters. More...
 
virtual void weightedInputDerivative (BatchInputType const &pattern, BatchOutputType const &outputs, BatchOutputType const &coefficients, State const &state, BatchInputType &derivative) const
 calculates the weighted sum of derivatives w.r.t the inputs More...
 
virtual void weightedDerivatives (BatchInputType const &patterns, BatchOutputType const &outputs, BatchOutputType const &coefficients, State const &state, RealVector &parameterDerivative, BatchInputType &inputDerivative) const
 calculates weighted input and parameter derivative at the same time More...
 
- Public Member Functions inherited from shark::IParameterizable< RealVector >
virtual ~IParameterizable ()
 
- Public Member Functions inherited from shark::INameable
virtual ~INameable ()
 
- Public Member Functions inherited from shark::ISerializable
virtual ~ISerializable ()
 Virtual d'tor. More...
 
void load (InArchive &archive, unsigned int version)
 Versioned loading of components, calls read(...). More...
 
void save (OutArchive &archive, unsigned int version) const
 Versioned storing of components, calls write(...). More...
 
 BOOST_SERIALIZATION_SPLIT_MEMBER ()
 

Additional Inherited Members

- Protected Attributes inherited from shark::AbstractModel< RealVector, LabelType >
Features m_features
 

Detailed Description

template<class LabelType>
class shark::CARTree< LabelType >

Classification and Regression Tree.

The CARTree predicts a class label using a decision tree

Definition at line 50 of file CARTree.h.

Member Typedef Documentation

◆ BatchInputType

template<class LabelType>
typedef base_type::BatchInputType shark::CARTree< LabelType >::BatchInputType

Definition at line 55 of file CARTree.h.

◆ BatchOutputType

template<class LabelType>
typedef base_type::BatchOutputType shark::CARTree< LabelType >::BatchOutputType

Definition at line 56 of file CARTree.h.

◆ TreeType

template<class LabelType>
typedef std::vector<Node> shark::CARTree< LabelType >::TreeType

Definition at line 72 of file CARTree.h.

Constructor & Destructor Documentation

◆ CARTree()

template<class LabelType>
shark::CARTree< LabelType >::CARTree ( std::size_t  inputDimension = 0)
inline

Constructor.

Definition at line 76 of file CARTree.h.

Member Function Documentation

◆ countAttributes()

template<class LabelType>
UIntVector shark::CARTree< LabelType >::countAttributes ( ) const
inline

Definition at line 139 of file CARTree.h.

◆ createRoot()

template<class LabelType>
Node& shark::CARTree< LabelType >::createRoot ( )
inline

Creates and returns an untyped root node (neither internal, nor leaf node)

Definition at line 183 of file CARTree.h.

◆ createState()

template<class LabelType>
boost::shared_ptr<State> shark::CARTree< LabelType >::createState ( ) const
inlinevirtual

Creates an internal state of the model.

The state is needed when the derivatives are to be calculated. Eval can store a state which is then reused to speed up the calculations of the derivatives. This also allows eval to be evaluated in parallel!

Reimplemented from shark::AbstractModel< RealVector, LabelType >.

Definition at line 82 of file CARTree.h.

◆ eval() [1/3]

template<class LabelType>
void shark::CARTree< LabelType >::eval ( BatchInputType const &  patterns,
BatchOutputType outputs 
) const
inlinevirtual

Evaluate the Tree on a batch of patterns.

Reimplemented from shark::AbstractModel< RealVector, LabelType >.

Definition at line 88 of file CARTree.h.

Referenced by shark::CARTree< unsigned int >::eval().

◆ eval() [2/3]

template<class LabelType>
void shark::CARTree< LabelType >::eval ( BatchInputType const &  patterns,
BatchOutputType outputs,
State state 
) const
inlinevirtual

Standard interface for evaluating the response of the model to a batch of patterns.

Parameters
patternsthe inputs of the model
outputsthe predictions or response of the model to every pattern
stateintermediate results stored by eval which can be reused for derivative computation.

Implements shark::AbstractModel< RealVector, LabelType >.

Definition at line 101 of file CARTree.h.

◆ eval() [3/3]

template<class LabelType>
void shark::CARTree< LabelType >::eval ( RealVector const &  pattern,
LabelType &  output 
)
inline

Evaluate the Tree on a single pattern.

Definition at line 105 of file CARTree.h.

◆ getLabel()

template<class LabelType>
LabelType const& shark::CARTree< LabelType >::getLabel ( std::size_t  nodeId) const
inline

Definition at line 177 of file CARTree.h.

◆ getNode() [1/2]

template<class LabelType>
Node& shark::CARTree< LabelType >::getNode ( std::size_t  nodeId)
inline

Returns the node with id nodeId.

Definition at line 167 of file CARTree.h.

Referenced by shark::CARTree< unsigned int >::reorderBFS().

◆ getNode() [2/2]

template<class LabelType>
Node const& shark::CARTree< LabelType >::getNode ( std::size_t  nodeId) const
inline

Returns the node with id nodeId.

Definition at line 172 of file CARTree.h.

◆ inputShape()

template<class LabelType>
Shape shark::CARTree< LabelType >::inputShape ( ) const
inlinevirtual

Return input dimension.

Implements shark::AbstractModel< RealVector, LabelType >.

Definition at line 151 of file CARTree.h.

◆ name()

template<class LabelType>
std::string shark::CARTree< LabelType >::name ( ) const
inlinevirtual

From INameable: return the class name.

Reimplemented from shark::INameable.

Definition at line 79 of file CARTree.h.

◆ numberOfNodes()

template<class LabelType>
std::size_t shark::CARTree< LabelType >::numberOfNodes ( ) const
inline

Definition at line 162 of file CARTree.h.

◆ numberOfParameters()

template<class LabelType>
std::size_t shark::CARTree< LabelType >::numberOfParameters ( ) const
inlinevirtual

The model does not have any parameters.

Reimplemented from shark::IParameterizable< RealVector >.

Definition at line 110 of file CARTree.h.

◆ outputShape()

template<class LabelType>
Shape shark::CARTree< LabelType >::outputShape ( ) const
inlinevirtual

Returns the shape of the output.

Implements shark::AbstractModel< RealVector, LabelType >.

Definition at line 154 of file CARTree.h.

◆ parameterVector()

template<class LabelType>
RealVector shark::CARTree< LabelType >::parameterVector ( ) const
inlinevirtual

The model does not have any parameters.

Reimplemented from shark::IParameterizable< RealVector >.

Definition at line 115 of file CARTree.h.

◆ read()

template<class LabelType>
void shark::CARTree< LabelType >::read ( InArchive archive)
inlinevirtual

from ISerializable, reads a model from an archive

Reimplemented from shark::AbstractModel< RealVector, LabelType >.

Definition at line 125 of file CARTree.h.

◆ reorderBFS()

template<class LabelType>
void shark::CARTree< LabelType >::reorderBFS ( )
inline

Reorders a tree into a breath-first-ordering.

This function call will remove all unreachable subtrees while reordering the nodes by their depth in the tree, i.e. first comes the root, the the children of the root, than their children, etc.

Definition at line 239 of file CARTree.h.

◆ setParameterVector()

template<class LabelType>
void shark::CARTree< LabelType >::setParameterVector ( RealVector const &  param)
inlinevirtual

The model does not have any parameters.

Reimplemented from shark::IParameterizable< RealVector >.

Definition at line 120 of file CARTree.h.

◆ transformInternalNode()

template<class LabelType>
Node& shark::CARTree< LabelType >::transformInternalNode ( std::size_t  nodeId,
std::size_t  attributeIndex,
double  attributeValue 
)
inline

Transforms an untyped node (no child, no internal node) into an internal node.

This creates already the two childs of the node, which are untyped.

Definition at line 196 of file CARTree.h.

◆ transformLeafNode()

template<class LabelType>
Node& shark::CARTree< LabelType >::transformLeafNode ( std::size_t  nodeId,
LabelType const &  label 
)
inline

Transforms a node (no leaf) into a leaf node and inserts the appropriate label.

If the node was an internal node before, its connections get removed and the childs are not reachable any more. Calling a reorder routine like reorderBFS() will get rid of those nodes.

Definition at line 226 of file CARTree.h.

◆ write()

template<class LabelType>
void shark::CARTree< LabelType >::write ( OutArchive archive) const
inlinevirtual

from ISerializable, writes a model to an archive

Reimplemented from shark::AbstractModel< RealVector, LabelType >.

Definition at line 132 of file CARTree.h.


The documentation for this class was generated from the following file: