QuickRank  v2.0
QuickRank: A C++ suite of Learning to Rank algorithms
ensemble.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 "learning/tree/rt.h"
25 #include "types.h"
26 #include "pugixml/src/pugixml.hpp"
27 
28 class Ensemble {
29 
30  public:
31  virtual ~Ensemble();
32  void set_capacity(const size_t n);
33  void push(RTNode *root, const double weight, const float maxlabel);
34  void pop();
35 
36  size_t get_size() const {
37  return size;
38  }
39 
40  bool is_notempty() const {
41  return size > 0;
42  }
43 
45  const size_t offset = 1) const;
46 
47  virtual std::shared_ptr<std::vector<quickrank::Score>>
49  const size_t offset = 1) const;
50 
51  pugi::xml_node append_xml_model(pugi::xml_node parent,
52  bool skip_useless_trees = true) const;
53 
54  virtual bool update_ensemble_weights(
55  std::shared_ptr<std::vector<double>> weights);
56 
57  virtual std::shared_ptr<std::vector<double>> get_weights() const;
58 
59  private:
60  struct wt {
61  wt(RTNode *root, double weight, float maxlabel)
62  : root(root),
63  weight(weight),
64  maxlabel(maxlabel) {
65  }
66  RTNode *root = NULL;
67  double weight = 0.0;
68  float maxlabel = 0.0f;
69  };
70  size_t size = 0;
71  wt *arr = NULL;
72 };
virtual bool update_ensemble_weights(std::shared_ptr< std::vector< double >> weights)
Definition: ensemble.cc:89
size_t get_size() const
Definition: ensemble.h:36
float Feature
data type for instance predicted label
Definition: types.h:31
Definition: ensemble.h:28
double Score
data type for instance truth label
Definition: types.h:30
pugi::xml_node append_xml_model(pugi::xml_node parent, bool skip_useless_trees=true) const
Definition: ensemble.cc:69
virtual std::shared_ptr< std::vector< quickrank::Score > > partial_scores_instance(const quickrank::Feature *d, const size_t offset=1) const
Definition: ensemble.cc:61
Definition: ensemble.h:60
void push(RTNode *root, const double weight, const float maxlabel)
Definition: ensemble.cc:42
bool is_notempty() const
Definition: ensemble.h:40
void set_capacity(const size_t n)
Definition: ensemble.cc:33
wt * arr
Definition: ensemble.h:71
size_t size
Definition: ensemble.h:70
virtual quickrank::Score score_instance(const quickrank::Feature *d, const size_t offset=1) const
Definition: ensemble.cc:51
void pop()
Definition: ensemble.cc:46
Definition: rtnode.h:36
virtual ~Ensemble()
Definition: ensemble.cc:27
virtual std::shared_ptr< std::vector< double > > get_weights() const
Definition: ensemble.cc:104
wt(RTNode *root, double weight, float maxlabel)
Definition: ensemble.h:61