CART Classifier. More...
#include <shark/Models/Trees/CARTClassifier.h>
Classes | |
struct | SplitInfo |
Public Types | |
typedef base_type::BatchInputType | BatchInputType |
typedef base_type::BatchOutputType | BatchOutputType |
typedef std::vector< SplitInfo > | SplitMatrixType |
![]() | |
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 (SplitMatrixType const &splitMatrix) | |
Constructor taking the splitMatrix as argument. More... | |
CARTClassifier (SplitMatrixType const &splitMatrix, bool optimize) | |
Constructor taking the splitMatrix as argument and optimize it if requested. More... | |
CARTClassifier (SplitMatrixType const &splitMatrix, std::size_t d) | |
Constructor taking the splitMatrix as argument as well as maximum number of attributes. More... | |
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 (const BatchInputType &patterns, BatchOutputType &outputs) const |
Evaluate the Tree on a batch of patterns. More... | |
void | eval (const BatchInputType &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 | setSplitMatrix (SplitMatrixType const &splitMatrix) |
Set the model split matrix. More... | |
SplitMatrixType | getSplitMatrix () const |
Get the model split matrix. 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 (const RealVector ¶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 (const RegressionDataset &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 (const ClassificationDataset &dataOOB) |
Compute feature importances, given an oob dataset (Classification) More... | |
void | computeFeatureImportances (const RegressionDataset &dataOOB) |
Compute feature importances, given an oob dataset (Regression) More... | |
![]() | |
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... | |
![]() | |
virtual | ~IParameterizable () |
![]() | |
virtual | ~INameable () |
![]() | |
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 split matrix. More... | |
void | optimizeSplitMatrix (SplitMatrixType &splitMatrix) const |
template<class Vector > | |
LabelType const & | evalPattern (Vector const &pattern) const |
Evaluate the CART tree on a single sample. More... | |
Protected Attributes | |
SplitMatrixType | m_splitMatrix |
split matrix of the model More... | |
std::size_t | m_inputDimension |
Number of attributes (set by trainer) More... | |
RealVector | m_featureImportances |
double | m_OOBerror |
![]() | |
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<SplitInfo> shark::CARTClassifier< LabelType >::SplitMatrixType |
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 94 of file CARTClassifier.h.
|
inline |
Constructor.
Definition at line 97 of file CARTClassifier.h.
|
inline |
Constructor taking the splitMatrix as argument.
Definition at line 101 of file CARTClassifier.h.
|
inline |
Constructor taking the splitMatrix as argument and optimize it if requested.
Definition at line 107 of file CARTClassifier.h.
|
inline |
Constructor taking the splitMatrix as argument as well as maximum number of attributes.
Definition at line 116 of file CARTClassifier.h.
|
inline |
Compute feature importances, given an oob dataset (Classification)
Definition at line 249 of file CARTClassifier.h.
|
inline |
Compute feature importances, given an oob dataset (Regression)
Definition at line 284 of file CARTClassifier.h.
|
inline |
Compute oob error, given an oob dataset (Classification)
Definition at line 215 of file CARTClassifier.h.
Referenced by shark::CARTClassifier< RealVector >::computeFeatureImportances().
|
inline |
Compute oob error, given an oob dataset (Regression)
Definition at line 227 of file CARTClassifier.h.
|
inline |
Definition at line 191 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 126 of file CARTClassifier.h.
|
inlinevirtual |
Evaluate the Tree on a batch of patterns.
Reimplemented from shark::AbstractModel< RealVector, LabelType >.
Definition at line 132 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 145 of file CARTClassifier.h.
|
inline |
Evaluate the Tree on a single pattern.
Definition at line 149 of file CARTClassifier.h.
|
inlineprotected |
Evaluate the CART tree on a single sample.
Definition at line 345 of file CARTClassifier.h.
Referenced by shark::CARTClassifier< RealVector >::eval().
|
inline |
Return feature importances.
Definition at line 244 of file CARTClassifier.h.
|
inlineprotected |
Finds the index of the node with a certain nodeID in an unoptimized split matrix.
Definition at line 323 of file CARTClassifier.h.
Referenced by shark::CARTClassifier< RealVector >::optimizeSplitMatrix().
|
inline |
Get the model split matrix.
Definition at line 160 of file CARTClassifier.h.
|
inline |
Return input dimension.
Definition at line 205 of file CARTClassifier.h.
|
inlinevirtual |
From INameable: return the class name.
Reimplemented from shark::INameable.
Definition at line 123 of file CARTClassifier.h.
|
inlinevirtual |
The model does not have any parameters.
Reimplemented from shark::IParameterizable.
Definition at line 165 of file CARTClassifier.h.
|
inline |
Return OOB error.
Definition at line 239 of file CARTClassifier.h.
|
inlineprotected |
Optimize a split matrix, 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 333 of file CARTClassifier.h.
Referenced by shark::CARTClassifier< RealVector >::setSplitMatrix().
|
inlinevirtual |
The model does not have any parameters.
Reimplemented from shark::IParameterizable.
Definition at line 170 of file CARTClassifier.h.
|
inlinevirtual |
from ISerializable, reads a model from an archive
Reimplemented from shark::AbstractModel< RealVector, LabelType >.
Definition at line 180 of file CARTClassifier.h.
|
inline |
Definition at line 210 of file CARTClassifier.h.
|
inlinevirtual |
The model does not have any parameters.
Reimplemented from shark::IParameterizable.
Definition at line 175 of file CARTClassifier.h.
|
inline |
Set the model split matrix.
Definition at line 154 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 185 of file CARTClassifier.h.
|
protected |
Definition at line 364 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 361 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 |
Definition at line 367 of file CARTClassifier.h.
Referenced by shark::CARTClassifier< RealVector >::computeFeatureImportances(), shark::CARTClassifier< RealVector >::computeOOBerror(), and shark::CARTClassifier< RealVector >::OOBerror().
|
protected |
split matrix of the model
Definition at line 320 of file CARTClassifier.h.
Referenced by shark::CARTClassifier< RealVector >::CARTClassifier(), shark::CARTClassifier< RealVector >::countAttributes(), shark::CARTClassifier< RealVector >::getSplitMatrix(), shark::CARTClassifier< RealVector >::read(), shark::CARTClassifier< RealVector >::setSplitMatrix(), and shark::CARTClassifier< RealVector >::write().