QuickRank  v2.0
QuickRank: A C++ suite of Learning to Rank algorithms
custom_ltr.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 
23 #pragma once
24 
25 #include <memory>
26 
27 #include "data/dataset.h"
28 #include "metric/ir/metric.h"
29 #include "learning/ltr_algorithm.h"
30 
31 namespace quickrank {
32 namespace learning {
33 
34 /*
35  * Command line
36  ./bin/quickrank --algo custom \
37  --train tests/data/msn1.fold1.train.5k.txt \
38  --valid tests/data/msn1.fold1.vali.5k.txt \
39  --test tests/data/msn1.fold1.test.5k.txt \
40  --model model.xml
41  */
42 
43 class CustomLTR: public LTR_Algorithm {
44 
45  public:
46  CustomLTR();
47 
48  CustomLTR(const pugi::xml_document &model) {
49  }
50 
51  virtual ~CustomLTR();
52 
53  /// Returns the name of the ranker.
54  virtual std::string name() const {
55  return NAME_;
56  }
57 
58  static const std::string NAME_;
59 
60  /// Executes the learning process.
61  ///
62  /// \param training_dataset The training dataset.
63  /// \param validation_dataset The validation training dataset.
64  /// \param metric The metric to be optimized.
65  /// \param partial_save Allows to save a partial model every given number of iterations.
66  /// \param model_filename The file where the model, and the partial models, are saved.
67  virtual void learn(std::shared_ptr<data::Dataset> training_dataset,
68  std::shared_ptr<data::Dataset> validation_dataset,
69  std::shared_ptr<metric::ir::Metric> metric,
70  size_t partial_save,
71  const std::string model_filename);
72 
73  /// Returns the score of a given document.
74  virtual Score score_document(const Feature *d) const;
75 
76  /// Return the xml model representing the current object
77  virtual pugi::xml_document *get_xml_model() const;
78 
79  /// \todo TODO: add load_model();
80 
81  const Score FIXED_SCORE = 666.0;
82 
83  private:
84 
85  /// The output stream operator.
86  friend std::ostream &operator<<(std::ostream &os, const CustomLTR &a) {
87  return a.put(os);
88  }
89 
90  /// Prints the description of Algorithm, including its parameters
91  virtual std::ostream &put(std::ostream &os) const;
92 };
93 
94 } // namespace learning
95 } // namespace quickrank
Definition: custom_ltr.h:43
Definition: dataset.cc:28
const Score FIXED_SCORE
Definition: custom_ltr.h:81
virtual void learn(std::shared_ptr< data::Dataset > training_dataset, std::shared_ptr< data::Dataset > validation_dataset, std::shared_ptr< metric::ir::Metric > metric, size_t partial_save, const std::string model_filename)
Executes the learning process.
Definition: custom_ltr.cc:44
virtual std::ostream & put(std::ostream &os) const
Prints the description of Algorithm, including its parameters.
Definition: custom_ltr.cc:39
static const std::string NAME_
Definition: custom_ltr.h:58
Definition: ltr_algorithm.h:33
virtual Score score_document(const Feature *d) const
Returns the score of a given document.
Definition: custom_ltr.cc:81
float Feature
data type for instance predicted label
Definition: types.h:31
CustomLTR(const pugi::xml_document &model)
Definition: custom_ltr.h:48
friend std::ostream & operator<<(std::ostream &os, const CustomLTR &a)
The output stream operator.
Definition: custom_ltr.h:86
double Score
data type for instance truth label
Definition: types.h:30
CustomLTR()
Definition: custom_ltr.cc:33
virtual std::string name() const
Returns the name of the ranker.
Definition: custom_ltr.h:54
virtual ~CustomLTR()
Definition: custom_ltr.cc:36
virtual pugi::xml_document * get_xml_model() const
Return the xml model representing the current object.
Definition: custom_ltr.cc:85