QuickRank  v2.0
QuickRank: A C++ suite of Learning to Rank algorithms
lambdamart.h
Go to the documentation of this file.
1 /*
2  * QuickRank - A C++ suite of Learning to Rank algorithms
3  * Webpage: http://quickrank.isti.cnr.it/
4  * Contact: quickrank@isti.cnr.it
5  *
6  * Unless explicitly acquired and licensed from Licensor under another
7  * license, the contents of this file are subject to the Reciprocal Public
8  * License ("RPL") Version 1.5, or subsequent versions as allowed by the RPL,
9  * and You may not copy or use this file in either source code or executable
10  * form, except in compliance with the terms and conditions of the RPL.
11  *
12  * All software distributed under the RPL is provided strictly on an "AS
13  * IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, AND
14  * LICENSOR HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
15  * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
16  * PURPOSE, QUIET ENJOYMENT, OR NON-INFRINGEMENT. See the RPL for specific
17  * language governing rights and limitations under the RPL.
18  *
19  * Contributor:
20  * HPC. Laboratory - ISTI - CNR - http://hpc.isti.cnr.it/
21  */
22 #pragma once
23 
24 #include "types.h"
25 #include "learning/forests/mart.h"
26 #include "learning/tree/rt.h"
27 #include "learning/tree/ensemble.h"
28 
29 namespace quickrank {
30 namespace learning {
31 namespace forests {
32 
33 class LambdaMart: public Mart {
34  public:
35  /// Initializes a new LambdaMart instance with the given learning parameters.
36  ///
37  /// \param ntrees Maximum number of trees.
38  /// \param shrinkage Learning rate.
39  /// \param nthresholds Number of bins in discretization. 0 means no discretization.
40  /// \param ntreeleaves Maximum number of leaves in each tree.
41  /// \param minleafsupport Minimum number of instances in each leaf.
42  /// \param esr Early stopping if no improvement after \esr iterations
43  /// on the validation set.
44  LambdaMart(size_t ntrees, double shrinkage, size_t nthresholds,
45  size_t ntreeleaves, size_t minleafsupport, size_t esr)
46  : Mart(ntrees, shrinkage, nthresholds, ntreeleaves, minleafsupport, esr) {
47  }
48 
49  /// Generates a LTR_Algorithm instance from a previously saved XML model.
50  LambdaMart(const pugi::xml_document &model)
51  : Mart(model) {
52  }
53 
54  virtual ~LambdaMart() {
55  }
56 
57  /// Returns the name of the ranker.
58  virtual std::string name() const {
59  return NAME_;
60  }
61 
62  static const std::string NAME_;
63 
64  protected:
65  /// Prepares private data structurs befor training takes place.
66  virtual void init(std::shared_ptr<data::VerticalDataset> training_dataset);
67 
68  /// De-allocates private data structure after training has taken place.
69  virtual void clear(size_t num_features);
70 
71  /// Computes pseudo responses.
72  ///
73  /// \param training_dataset The training data.
74  /// \param metric The metric to be optimized.
75  virtual void compute_pseudoresponses(
76  std::shared_ptr<data::VerticalDataset> training_dataset,
77  metric::ir::Metric *metric);
78 
79  /// Fits a regression tree on the gradient given by the pseudo residuals
80  ///
81  /// \param training_dataset The dataset used for training
82  virtual std::unique_ptr<RegressionTree> fit_regressor_on_gradient(
83  std::shared_ptr<data::VerticalDataset> training_dataset);
84 
85  protected:
86  double *instance_weights_ = NULL; //corresponds to datapoint.cache
87 
88 };
89 
90 } // namespace forests
91 } // namespace learning
92 } // namespace quickrank
virtual std::unique_ptr< RegressionTree > fit_regressor_on_gradient(std::shared_ptr< data::VerticalDataset > training_dataset)
Fits a regression tree on the gradient given by the pseudo residuals.
Definition: lambdamart.cc:47
Definition: dataset.cc:28
static const std::string NAME_
Definition: lambdamart.h:62
This class implements the basic functionalities of an IR evaluation metric.
Definition: metric.h:43
LambdaMart(const pugi::xml_document &model)
Generates a LTR_Algorithm instance from a previously saved XML model.
Definition: lambdamart.h:50
virtual void compute_pseudoresponses(std::shared_ptr< data::VerticalDataset > training_dataset, metric::ir::Metric *metric)
Computes pseudo responses.
Definition: lambdamart.cc:61
virtual std::string name() const
Returns the name of the ranker.
Definition: lambdamart.h:58
LambdaMart(size_t ntrees, double shrinkage, size_t nthresholds, size_t ntreeleaves, size_t minleafsupport, size_t esr)
Initializes a new LambdaMart instance with the given learning parameters.
Definition: lambdamart.h:44
Definition: lambdamart.h:33
double * instance_weights_
Definition: lambdamart.h:86
virtual void clear(size_t num_features)
De-allocates private data structure after training has taken place.
Definition: lambdamart.cc:41
virtual ~LambdaMart()
Definition: lambdamart.h:54
virtual void init(std::shared_ptr< data::VerticalDataset > training_dataset)
Prepares private data structurs befor training takes place.
Definition: lambdamart.cc:35