Classification and Regression Tree. More...
#include <shark/Models/Trees/CARTree.h>
Classes | |
struct | Node |
Public Types | |
typedef base_type::BatchInputType | BatchInputType |
typedef base_type::BatchOutputType | BatchOutputType |
typedef std::vector< Node > | TreeType |
Public Types inherited from shark::AbstractModel< RealVector, LabelType > | |
enum | Feature |
typedef RealVector | InputType |
Defines the input type of the model. | |
typedef LabelType | OutputType |
Defines the output type of the model. | |
typedef AbstractModel< RealVector, LabelType, RealVector > | ModelBaseType |
Defines the BaseType used by the model (this type). Useful for creating derived models. | |
typedef Batch< InputType >::type | BatchInputType |
defines the batch type of the input type. | |
typedef Batch< OutputType >::type | BatchOutputType |
defines the batch type of the output type | |
typedef TypedFlags< Feature > | Features |
typedef TypedFeatureNotAvailableException< Feature > | FeatureNotAvailableException |
Public Types inherited from shark::IParameterizable< VectorType > | |
typedef VectorType | ParameterVectorType |
Public Member Functions | |
CARTree () | |
Constructor. | |
CARTree (std::size_t inputDimension, Shape const &outputShape) | |
std::string | name () const |
From INameable: return the class name. | |
boost::shared_ptr< State > | createState () const |
Creates an internal state of the model. | |
void | eval (BatchInputType const &patterns, BatchOutputType &outputs) const |
Evaluate the Tree on a batch of patterns. | |
void | eval (BatchInputType const &patterns, BatchOutputType &outputs, State &state) const |
Standard interface for evaluating the response of the model to a batch of patterns. | |
void | eval (RealVector const &pattern, LabelType &output) |
Evaluate the Tree on a single pattern. | |
std::size_t | numberOfParameters () const |
The model does not have any parameters. | |
RealVector | parameterVector () const |
The model does not have any parameters. | |
void | setParameterVector (RealVector const ¶m) |
The model does not have any parameters. | |
void | read (InArchive &archive) |
from ISerializable, reads a model from an archive | |
void | write (OutArchive &archive) const |
from ISerializable, writes a model to an archive | |
UIntVector | countAttributes () const |
Shape | inputShape () const |
Return input dimension. | |
Shape | outputShape () const |
Returns the shape of the output. | |
std::size_t | numberOfNodes () const |
Node & | getNode (std::size_t nodeId) |
Returns the node with id nodeId. | |
Node const & | getNode (std::size_t nodeId) const |
Returns the node with id nodeId. | |
LabelType const & | getLabel (std::size_t nodeId) const |
Node & | createRoot () |
Creates and returns an untyped root node (neither internal, nor leaf node) | |
Node & | transformInternalNode (std::size_t nodeId, std::size_t attributeIndex, double attributeValue) |
Transforms an untyped node (no child, no internal node) into an internal node. | |
Node & | transformLeafNode (std::size_t nodeId, LabelType const &label) |
Transforms a node (no leaf) into a leaf node and inserts the appropriate label. | |
void | reorderBFS () |
Reorders a tree into a breath-first-ordering. | |
template<class Vector > | |
std::size_t | findLeaf (Vector const &pattern) const |
Find the leaf of the tree for a sample. | |
Public Member Functions inherited from shark::AbstractModel< RealVector, LabelType > | |
AbstractModel () | |
virtual | ~AbstractModel () |
const Features & | features () const |
virtual void | updateFeatures () |
bool | hasFirstParameterDerivative () const |
Returns true when the first parameter derivative is implemented. | |
bool | hasFirstInputDerivative () const |
Returns true when the first input derivative is implemented. | |
virtual void | eval (InputType const &pattern, OutputType &output) const |
Standard interface for evaluating the response of the model to a single pattern. | |
Data< OutputType > | operator() (Data< InputType > const &patterns) const |
Model evaluation as an operator for a whole dataset. This is a convenience function. | |
OutputType | operator() (InputType const &pattern) const |
Model evaluation as an operator for a single pattern. This is a convenience function. | |
BatchOutputType | operator() (BatchInputType const &patterns) const |
Model evaluation as an operator for a single pattern. This is a convenience function. | |
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. | |
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 | |
virtual void | weightedDerivatives (BatchInputType const &patterns, BatchOutputType const &outputs, BatchOutputType const &coefficients, State const &state, RealVector ¶meterDerivative, BatchInputType &inputDerivative) const |
calculates weighted input and parameter derivative at the same time | |
Public Member Functions inherited from shark::IParameterizable< VectorType > | |
virtual | ~IParameterizable () |
Public Member Functions inherited from shark::INameable | |
virtual | ~INameable () |
Public Member Functions inherited from shark::ISerializable | |
virtual | ~ISerializable () |
Virtual d'tor. | |
void | load (InArchive &archive, unsigned int version) |
Versioned loading of components, calls read(...). | |
void | save (OutArchive &archive, unsigned int version) const |
Versioned storing of components, calls write(...). | |
BOOST_SERIALIZATION_SPLIT_MEMBER () | |
Additional Inherited Members | |
Protected Attributes inherited from shark::AbstractModel< RealVector, LabelType > | |
Features | m_features |
Classification and Regression Tree.
typedef base_type::BatchInputType shark::CARTree< LabelType >::BatchInputType |
typedef base_type::BatchOutputType shark::CARTree< LabelType >::BatchOutputType |
typedef std::vector<Node> shark::CARTree< LabelType >::TreeType |
|
inline |
|
inline |
|
inline |
Definition at line 147 of file CARTree.h.
References SHARK_ASSERT.
|
inline |
Creates and returns an untyped root node (neither internal, nor leaf node)
Definition at line 191 of file CARTree.h.
References shark::CARTree< LabelType >::Node::leftId, and shark::CARTree< LabelType >::Node::rightIdOrIndex.
|
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 >.
|
inlinevirtual |
Evaluate the Tree on a batch of patterns.
Reimplemented from shark::AbstractModel< RealVector, LabelType >.
Definition at line 94 of file CARTree.h.
References shark::getBatchElement().
Referenced by shark::CARTree< LabelType >::eval().
|
inlinevirtual |
Standard interface for evaluating the response of the model to a batch of patterns.
patterns | the inputs of the model |
outputs | the predictions or response of the model to every pattern |
state | intermediate results stored by eval which can be reused for derivative computation. |
Implements shark::AbstractModel< RealVector, LabelType >.
Definition at line 107 of file CARTree.h.
References shark::CARTree< LabelType >::eval().
|
inline |
|
inline |
|
inline |
Definition at line 185 of file CARTree.h.
References SIZE_CHECK.
|
inline |
Returns the node with id nodeId.
Definition at line 175 of file CARTree.h.
References SIZE_CHECK.
Referenced by shark::CARTree< LabelType >::reorderBFS().
|
inline |
|
inlinevirtual |
Return input dimension.
Implements shark::AbstractModel< RealVector, LabelType >.
|
inlinevirtual |
From INameable: return the class name.
Reimplemented from shark::INameable.
|
inline |
|
inlinevirtual |
The model does not have any parameters.
Reimplemented from shark::IParameterizable< VectorType >.
|
inlinevirtual |
Returns the shape of the output.
Implements shark::AbstractModel< RealVector, LabelType >.
|
inlinevirtual |
The model does not have any parameters.
Reimplemented from shark::IParameterizable< VectorType >.
|
inlinevirtual |
from ISerializable, reads a model from an archive
Reimplemented from shark::AbstractModel< RealVector, LabelType >.
|
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 249 of file CARTree.h.
References shark::CARTree< LabelType >::getNode(), shark::CARTree< LabelType >::Node::leftId, and shark::CARTree< LabelType >::Node::rightIdOrIndex.
|
inlinevirtual |
The model does not have any parameters.
Reimplemented from shark::IParameterizable< VectorType >.
Definition at line 126 of file CARTree.h.
References SHARK_ASSERT.
|
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 204 of file CARTree.h.
References shark::CARTree< LabelType >::Node::leftId, and shark::CARTree< LabelType >::Node::rightIdOrIndex.
|
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 234 of file CARTree.h.
References shark::CARTree< LabelType >::Node::attributeIndex, shark::CARTree< LabelType >::Node::leftId, and shark::CARTree< LabelType >::Node::rightIdOrIndex.
|
inlinevirtual |
from ISerializable, writes a model to an archive
Reimplemented from shark::AbstractModel< RealVector, LabelType >.