CART Classifier. More...
#include <shark/Models/Trees/CARTClassifier.h>
Classes | |
struct | NodeInfo |
Public Types | |
typedef base_type::BatchInputType | BatchInputType |
typedef base_type::BatchOutputType | BatchOutputType |
typedef std::vector< NodeInfo > | TreeType |
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 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< Feature > | Features |
typedef TypedFeatureNotAvailableException< Feature > | FeatureNotAvailableException |
Public Member Functions | |
CARTClassifier () | |
Constructor. More... | |
CARTClassifier (TreeType const &tree) | |
Constructor taking the tree as argument. More... | |
CARTClassifier (TreeType &&tree) | |
CARTClassifier (TreeType const &tree, bool optimize) | |
Constructor taking the tree as argument and optimize it if requested. More... | |
CARTClassifier (TreeType const &tree, std::size_t d) | |
Constructor taking the tree as argument as well as maximum number of attributes. More... | |
CARTClassifier (TreeType &&tree, std::size_t d) BOOST_NOEXCEPT_IF((std | |
std::string | name () const |
From INameable: return the class name. More... | |
boost::shared_ptr< State > | createState () 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... | |
void | setTree (TreeType const &tree) |
Set the model tree. More... | |
TreeType | getTree () const |
Get the model tree. 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 ¶m) |
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 |
std::size_t | inputSize () const |
Return input dimension. More... | |
void | setInputDimension (std::size_t d) |
void | computeOOBerror (const ClassificationDataset &dataOOB) |
Compute oob error, given an oob dataset (Classification) More... | |
void | computeOOBerror (RegressionDataset const &dataOOB) |
Compute oob error, given an oob dataset (Regression) More... | |
double | OOBerror () const |
Return OOB error. More... | |
RealVector const & | featureImportances () const |
Return feature importances. More... | |
void | computeFeatureImportances (ClassificationDataset const &dataOOB, random::rng_type &rng) |
Compute feature importances, given an oob dataset (Classification) More... | |
void | computeFeatureImportances (RegressionDataset const &dataOOB, random::rng_type &rng) |
Compute feature importances, given an oob dataset (Regression) More... | |
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. More... | |
bool | hasSecondParameterDerivative () const |
Returns true when the second parameter derivative is implemented. More... | |
bool | hasFirstInputDerivative () const |
Returns true when the first input derivative is implemented. More... | |
bool | hasSecondInputDerivative () const |
Returns true when the second parameter derivative is implemented. More... | |
bool | isSequential () const |
virtual void | eval (InputType const &pattern, OutputType &output) const |
Standard interface for evaluating the response of the model to a single pattern. More... | |
Data< OutputType > | operator() (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 &coefficients, State const &state, RealVector &derivative) const |
calculates the weighted sum of derivatives w.r.t the parameters. More... | |
virtual void | weightedParameterDerivative (BatchInputType const &pattern, BatchOutputType const &coefficients, Batch< RealMatrix >::type const &errorHessian, State const &state, RealVector &derivative, RealMatrix &hessian) const |
calculates the weighted sum of derivatives w.r.t the parameters More... | |
virtual void | weightedInputDerivative (BatchInputType const &pattern, BatchOutputType const &coefficients, State const &state, BatchInputType &derivative) const |
calculates the weighted sum of derivatives w.r.t the inputs More... | |
virtual void | weightedInputDerivative (BatchInputType const &pattern, BatchOutputType const &coefficients, typename Batch< RealMatrix >::type const &errorHessian, State const &state, RealMatrix &derivative, Batch< RealMatrix >::type &hessian) const |
calculates the weighted sum of derivatives w.r.t the inputs More... | |
virtual void | weightedDerivatives (BatchInputType const &patterns, BatchOutputType const &coefficients, State const &state, RealVector ¶meterDerivative, BatchInputType &inputDerivative) const |
calculates weighted input and parameter derivative at the same time More... | |
Public Member Functions inherited from shark::IParameterizable | |
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 () | |
Protected Member Functions | |
std::size_t | findNode (std::size_t nodeId) const |
Finds the index of the node with a certain nodeID in an unoptimized tree. More... | |
void | optimizeTree (TreeType &tree) const |
template<class Vector > | |
LabelType const & | evalPattern (Vector const &pattern) const |
Evaluate the CART tree on a single sample. More... | |
Protected Attributes | |
TreeType | m_tree |
tree of the model More... | |
std::size_t | m_inputDimension |
Number of attributes (set by trainer) More... | |
RealVector | m_featureImportances |
double | m_OOBerror |
Protected Attributes inherited from shark::AbstractModel< RealVector, LabelType > | |
Features | m_features |
CART Classifier.
Definition at line 58 of file CARTClassifier.h.
typedef base_type::BatchInputType shark::CARTClassifier< LabelType >::BatchInputType |
Definition at line 63 of file CARTClassifier.h.
typedef base_type::BatchOutputType shark::CARTClassifier< LabelType >::BatchOutputType |
Definition at line 64 of file CARTClassifier.h.
typedef std::vector<NodeInfo> shark::CARTClassifier< LabelType >::TreeType |
Vector of structs that contains the splitting information and the labels. The class label is a normalized histogram in the classification case. In the regression case, the label is the regression value.
Definition at line 121 of file CARTClassifier.h.
|
inline |
Constructor.
Definition at line 124 of file CARTClassifier.h.
|
inlineexplicit |
Constructor taking the tree as argument.
Definition at line 128 of file CARTClassifier.h.
|
inlineexplicit |
Definition at line 131 of file CARTClassifier.h.
|
inline |
Constructor taking the tree as argument and optimize it if requested.
Definition at line 136 of file CARTClassifier.h.
|
inline |
Constructor taking the tree as argument as well as maximum number of attributes.
Definition at line 145 of file CARTClassifier.h.
|
inline |
Definition at line 151 of file CARTClassifier.h.
|
inline |
Compute feature importances, given an oob dataset (Classification)
Definition at line 284 of file CARTClassifier.h.
|
inline |
Compute feature importances, given an oob dataset (Regression)
Definition at line 319 of file CARTClassifier.h.
|
inline |
Compute oob error, given an oob dataset (Classification)
Definition at line 250 of file CARTClassifier.h.
Referenced by shark::CARTClassifier< RealVector >::computeFeatureImportances().
|
inline |
Compute oob error, given an oob dataset (Regression)
Definition at line 262 of file CARTClassifier.h.
|
inline |
Definition at line 226 of file CARTClassifier.h.
|
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 161 of file CARTClassifier.h.
|
inlinevirtual |
Evaluate the Tree on a batch of patterns.
Reimplemented from shark::AbstractModel< RealVector, LabelType >.
Definition at line 167 of file CARTClassifier.h.
Referenced by shark::CARTClassifier< RealVector >::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 180 of file CARTClassifier.h.
|
inline |
Evaluate the Tree on a single pattern.
Definition at line 184 of file CARTClassifier.h.
|
inlineprotected |
Evaluate the CART tree on a single sample.
Definition at line 380 of file CARTClassifier.h.
Referenced by shark::CARTClassifier< RealVector >::eval().
|
inline |
Return feature importances.
Definition at line 279 of file CARTClassifier.h.
|
inlineprotected |
Finds the index of the node with a certain nodeID in an unoptimized tree.
Definition at line 358 of file CARTClassifier.h.
Referenced by shark::CARTClassifier< RealVector >::optimizeTree().
|
inline |
Get the model tree.
Definition at line 195 of file CARTClassifier.h.
|
inline |
Return input dimension.
Definition at line 240 of file CARTClassifier.h.
|
inlinevirtual |
From INameable: return the class name.
Reimplemented from shark::INameable.
Definition at line 158 of file CARTClassifier.h.
|
inlinevirtual |
The model does not have any parameters.
Reimplemented from shark::IParameterizable.
Definition at line 200 of file CARTClassifier.h.
|
inline |
Return OOB error.
Definition at line 274 of file CARTClassifier.h.
|
inlineprotected |
Optimize a tree, so constant lookup can be used. The optimization is done by changing the index of the children to use indices instead of node ID. Furthermore, the node IDs are converted to index numbers.
Definition at line 368 of file CARTClassifier.h.
Referenced by shark::CARTClassifier< RealVector >::CARTClassifier(), and shark::CARTClassifier< RealVector >::setTree().
|
inlinevirtual |
The model does not have any parameters.
Reimplemented from shark::IParameterizable.
Definition at line 205 of file CARTClassifier.h.
|
inlinevirtual |
from ISerializable, reads a model from an archive
Reimplemented from shark::AbstractModel< RealVector, LabelType >.
Definition at line 215 of file CARTClassifier.h.
|
inline |
Definition at line 245 of file CARTClassifier.h.
|
inlinevirtual |
The model does not have any parameters.
Reimplemented from shark::IParameterizable.
Definition at line 210 of file CARTClassifier.h.
|
inline |
Set the model tree.
Definition at line 189 of file CARTClassifier.h.
Referenced by shark::CARTClassifier< RealVector >::CARTClassifier().
|
inlinevirtual |
from ISerializable, writes a model to an archive
Reimplemented from shark::AbstractModel< RealVector, LabelType >.
Definition at line 220 of file CARTClassifier.h.
|
protected |
Definition at line 399 of file CARTClassifier.h.
Referenced by shark::CARTClassifier< RealVector >::computeFeatureImportances(), and shark::CARTClassifier< RealVector >::featureImportances().
|
protected |
Number of attributes (set by trainer)
Definition at line 396 of file CARTClassifier.h.
Referenced by shark::CARTClassifier< RealVector >::CARTClassifier(), shark::CARTClassifier< RealVector >::computeFeatureImportances(), shark::CARTClassifier< RealVector >::countAttributes(), shark::CARTClassifier< RealVector >::inputSize(), and shark::CARTClassifier< RealVector >::setInputDimension().
|
protected |
|
protected |
tree of the model
Definition at line 355 of file CARTClassifier.h.
Referenced by shark::CARTClassifier< RealVector >::CARTClassifier(), shark::CARTClassifier< RealVector >::countAttributes(), shark::CARTClassifier< RealVector >::getTree(), shark::CARTClassifier< RealVector >::read(), shark::CARTClassifier< RealVector >::setTree(), and shark::CARTClassifier< RealVector >::write().