QuickRank  v2.0
QuickRank: A C++ suite of Learning to Rank algorithms
Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | Friends | List of all members
quickrank::learning::forests::Mart Class Reference

#include <mart.h>

Inheritance diagram for quickrank::learning::forests::Mart:
quickrank::learning::LTR_Algorithm quickrank::learning::forests::LambdaMart quickrank::learning::forests::ObliviousMart quickrank::learning::forests::ObliviousLambdaMart

Public Member Functions

 Mart (size_t ntrees, double shrinkage, size_t nthresholds, size_t ntreeleaves, size_t minleafsupport, size_t valid_iterations)
 Initializes a new Mart instance with the given learning parameters. More...
 
 Mart (const pugi::xml_document &model)
 Generates a LTR_Algorithm instance from a previously saved XML model. More...
 
virtual ~Mart ()
 
virtual void learn (std::shared_ptr< data::Dataset > training_dataset, std::shared_ptr< data::Dataset > validation_dataset, std::shared_ptr< metric::ir::Metric > training_metric, size_t partial_save, const std::string output_basename)
 Start the learning process. More...
 
virtual Score score_document (const Feature *d) const
 Returns the score by the current ranker. More...
 
virtual std::shared_ptr< std::vector< Score > > partial_scores_document (const Feature *d) const
 Returns the partial scores of a given document, tree. More...
 
virtual void print_additional_stats (void) const
 Print additional statistics. More...
 
virtual std::string name () const
 Returns the name of the ranker. More...
 
virtual bool update_weights (std::shared_ptr< std::vector< double >> weights)
 Update the weights for the ensemble models (only). More...
 
virtual std::shared_ptr< std::vector< double > > get_weights () const
 Return the weights for the ensemble models (only). More...
 
- Public Member Functions inherited from quickrank::learning::LTR_Algorithm
 LTR_Algorithm ()
 
 LTR_Algorithm (const pugi::xml_document &model)
 Generates a LTR_Algorithm instance from a previously saved XML model. More...
 
virtual ~LTR_Algorithm ()
 
 LTR_Algorithm (const LTR_Algorithm &other)=delete
 Avoid inefficient copy constructor. More...
 
LTR_Algorithmoperator= (const LTR_Algorithm &)=delete
 Avoid inefficient copy assignment. More...
 
virtual void score_dataset (std::shared_ptr< data::Dataset > dataset, Score *scores) const
 Given and input dateset, the current ranker generates scores for each instance and store the in the scores vector. More...
 
virtual void save (std::string model_filename, int suffix=-1) const
 Save the current model to the output_file. More...
 

Static Public Attributes

static const std::string NAME_ = "MART"
 

Protected Member Functions

virtual void init (std::shared_ptr< data::VerticalDataset > training_dataset)
 Prepares private data structures before training takes place. More...
 
virtual void clear (size_t num_features)
 De-allocates private data structure after training has taken place. More...
 
virtual void compute_pseudoresponses (std::shared_ptr< data::VerticalDataset > training_dataset, metric::ir::Metric *metric)
 Computes pseudo responses. More...
 
virtual std::unique_ptr< RegressionTreefit_regressor_on_gradient (std::shared_ptr< data::VerticalDataset > training_dataset)
 Fits a regression tree on the gradient given by the pseudo residuals. More...
 
virtual void update_modelscores (std::shared_ptr< data::Dataset > dataset, Score *scores, RegressionTree *tree)
 Updates scores with the last learnt regression tree. More...
 
virtual void update_modelscores (std::shared_ptr< data::VerticalDataset > dataset, Score *scores, RegressionTree *tree)
 
virtual pugi::xml_document * get_xml_model () const
 Return the xml model representing the current object. More...
 

Protected Attributes

float ** thresholds_ = NULL
 
size_t * thresholds_size_ = NULL
 
double * scores_on_training_ = NULL
 
quickrank::Scorescores_on_validation_ = NULL
 
size_t validation_bestmodel_ = 0
 
double * pseudoresponses_ = NULL
 
Ensemble ensemble_model_
 
size_t ntrees_
 
double shrinkage_
 
size_t nthresholds_
 
size_t nleaves_
 
size_t minleafsupport_
 
size_t valid_iterations_
 
size_t ** sortedsid_ = NULL
 
size_t sortedsize_ = 0
 
RTRootHistogramhist_ = NULL
 

Private Member Functions

virtual std::ostream & put (std::ostream &os) const
 Prints the description of Algorithm, including its parameters. More...
 

Friends

std::ostream & operator<< (std::ostream &os, const Mart &a)
 The output stream operator. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from quickrank::learning::LTR_Algorithm
static std::shared_ptr< LTR_Algorithmload_model_from_file (std::string model_filename)
 Load a model from a given XML file. More...
 

Constructor & Destructor Documentation

quickrank::learning::forests::Mart::Mart ( size_t  ntrees,
double  shrinkage,
size_t  nthresholds,
size_t  ntreeleaves,
size_t  minleafsupport,
size_t  valid_iterations 
)
inline

Initializes a new Mart instance with the given learning parameters.

Parameters
ntreesMaximum number of trees.
shrinkageLearning rate.
nthresholdsNumber of bins in discretization. 0 means no discretization.
ntreeleavesMaximum number of leaves in each tree.
minleafsupportMinimum number of instances in each leaf.
valid_iterationsEarly stopping if no improvement after iterations on the validation set.
quickrank::learning::forests::Mart::Mart ( const pugi::xml_document &  model)

Generates a LTR_Algorithm instance from a previously saved XML model.

virtual quickrank::learning::forests::Mart::~Mart ( )
inlinevirtual

Member Function Documentation

void quickrank::learning::forests::Mart::clear ( size_t  num_features)
protectedvirtual

De-allocates private data structure after training has taken place.

Reimplemented in quickrank::learning::forests::LambdaMart.

void quickrank::learning::forests::Mart::compute_pseudoresponses ( std::shared_ptr< data::VerticalDataset training_dataset,
metric::ir::Metric metric 
)
protectedvirtual

Computes pseudo responses.

Parameters
training_datasetThe training data.
metricThe metric to be optimized.

Reimplemented in quickrank::learning::forests::LambdaMart.

std::unique_ptr< RegressionTree > quickrank::learning::forests::Mart::fit_regressor_on_gradient ( std::shared_ptr< data::VerticalDataset training_dataset)
protectedvirtual

Fits a regression tree on the gradient given by the pseudo residuals.

Parameters
training_datasetThe dataset used for training
Todo:
TODO: memory management of regression tree is wrong!!!

Reimplemented in quickrank::learning::forests::LambdaMart, quickrank::learning::forests::ObliviousLambdaMart, and quickrank::learning::forests::ObliviousMart.

virtual std::shared_ptr<std::vector<double> > quickrank::learning::forests::Mart::get_weights ( ) const
inlinevirtual

Return the weights for the ensemble models (only).

Default implementation will do nothing (default for non ensemble models).

Reimplemented from quickrank::learning::LTR_Algorithm.

pugi::xml_document * quickrank::learning::forests::Mart::get_xml_model ( ) const
protectedvirtual

Return the xml model representing the current object.

Implements quickrank::learning::LTR_Algorithm.

Reimplemented in quickrank::learning::forests::ObliviousMart, and quickrank::learning::forests::ObliviousLambdaMart.

void quickrank::learning::forests::Mart::init ( std::shared_ptr< data::VerticalDataset training_dataset)
protectedvirtual

Prepares private data structures before training takes place.

Reimplemented in quickrank::learning::forests::LambdaMart.

void quickrank::learning::forests::Mart::learn ( std::shared_ptr< data::Dataset training_dataset,
std::shared_ptr< data::Dataset validation_dataset,
std::shared_ptr< metric::ir::Metric training_metric,
size_t  partial_save,
const std::string  output_basename 
)
virtual

Start the learning process.

Implements quickrank::learning::LTR_Algorithm.

virtual std::string quickrank::learning::forests::Mart::name ( ) const
inlinevirtual
virtual std::shared_ptr<std::vector<Score> > quickrank::learning::forests::Mart::partial_scores_document ( const Feature d) const
inlinevirtual

Returns the partial scores of a given document, tree.

Parameters
dis a pointer to the document to be evaluated
next_fx_offsetThe offset to the next feature in the data representation.
Note
Each algorithm has a different implementation.

Reimplemented from quickrank::learning::LTR_Algorithm.

void quickrank::learning::forests::Mart::print_additional_stats ( void  ) const
virtual

Print additional statistics.

At the moment this include only number of comparisons for tree-based algorithms.

Reimplemented from quickrank::learning::LTR_Algorithm.

std::ostream & quickrank::learning::forests::Mart::put ( std::ostream &  os) const
privatevirtual

Prints the description of Algorithm, including its parameters.

Implements quickrank::learning::LTR_Algorithm.

Reimplemented in quickrank::learning::forests::ObliviousLambdaMart, and quickrank::learning::forests::ObliviousMart.

virtual Score quickrank::learning::forests::Mart::score_document ( const Feature d) const
inlinevirtual

Returns the score by the current ranker.

Parameters
dDocument to be scored.

Implements quickrank::learning::LTR_Algorithm.

void quickrank::learning::forests::Mart::update_modelscores ( std::shared_ptr< data::Dataset dataset,
Score scores,
RegressionTree tree 
)
protectedvirtual

Updates scores with the last learnt regression tree.

Parameters
datasetDataset to be scored.
scoresScores vector to be updated.
treeLast regression tree leartn.
void quickrank::learning::forests::Mart::update_modelscores ( std::shared_ptr< data::VerticalDataset dataset,
Score scores,
RegressionTree tree 
)
protectedvirtual
bool quickrank::learning::forests::Mart::update_weights ( std::shared_ptr< std::vector< double >>  weights)
virtual

Update the weights for the ensemble models (only).

Default implementation will do nothing (default for non ensemble models).

Reimplemented from quickrank::learning::LTR_Algorithm.

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const Mart a 
)
friend

The output stream operator.

Member Data Documentation

Ensemble quickrank::learning::forests::Mart::ensemble_model_
protected
RTRootHistogram* quickrank::learning::forests::Mart::hist_ = NULL
protected
size_t quickrank::learning::forests::Mart::minleafsupport_
protected
const std::string quickrank::learning::forests::Mart::NAME_ = "MART"
static
size_t quickrank::learning::forests::Mart::nleaves_
protected
size_t quickrank::learning::forests::Mart::nthresholds_
protected
size_t quickrank::learning::forests::Mart::ntrees_
protected
double* quickrank::learning::forests::Mart::pseudoresponses_ = NULL
protected
double* quickrank::learning::forests::Mart::scores_on_training_ = NULL
protected
quickrank::Score* quickrank::learning::forests::Mart::scores_on_validation_ = NULL
protected
double quickrank::learning::forests::Mart::shrinkage_
protected
size_t** quickrank::learning::forests::Mart::sortedsid_ = NULL
protected
size_t quickrank::learning::forests::Mart::sortedsize_ = 0
protected
float** quickrank::learning::forests::Mart::thresholds_ = NULL
protected
size_t* quickrank::learning::forests::Mart::thresholds_size_ = NULL
protected
size_t quickrank::learning::forests::Mart::valid_iterations_
protected
size_t quickrank::learning::forests::Mart::validation_bestmodel_ = 0
protected

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