QuickRank  v2.0
QuickRank: A C++ suite of Learning to Rank algorithms
queryresults.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 <algorithm>
25 
26 #include "types.h"
27 
28 namespace quickrank {
29 namespace data {
30 
31 /// This class wraps a set of results for a given query.
32 ///
33 /// The internal data representation is the same as the
34 /// \a Dataset it comes from.
35 /// \todo TODO: it seems we need also a class withouth features
36 class QueryResults {
37  public:
38 
39  /// Allocates an Query Results Object.
40  ///
41  /// This is used to store a the set of instances and their labels
42  /// related to a specific query.
43  /// \param n_instances The number of training instances (lines) in the dataset.
44  /// \param n_features The number of features.
45  QueryResults(size_t n_results, Label *new_labels,
46  Feature *new_features);
47  virtual ~QueryResults();
48 
49  Feature *features() const {
50  return features_;
51  }
52  Label *labels() const {
53  return labels_;
54  }
55  size_t num_results() const {
56  return num_results_;
57  }
58 
59  /// Sorts the element of the current result list
60  /// in descending order of the given \a scores vector
61  /// and stores in \a dest the positions of the sorted labels.
62  ///
63  /// \param scores vector of scores used for reverse sorting.
64  /// \param dest output of the sorting indexing.
65  void indexing_of_sorted_labels(const Score *scores, size_t *dest) const;
66 
67  /// Sorts the element of the current result list
68  /// in descending order of the given \a scores vector
69  /// and stores the resulting sorted labels in \a dest.
70  ///
71  /// \param scores vector of scores used for reverse sorting.
72  /// \param dest output of the labels sorting.
73  /// \param cutoff number of labels of interest, i.e., length of \a dest.
74  void sorted_labels(const Score *scores, Label *dest,
75  const size_t cutoff) const;
76 
77  private:
80  size_t num_results_;
81 
82 };
83 
84 } // namespace data
85 } // namespace quickrank
Label * labels() const
Definition: queryresults.h:52
Definition: dataset.cc:28
void indexing_of_sorted_labels(const Score *scores, size_t *dest) const
Sorts the element of the current result list in descending order of the given scores vector and store...
Definition: queryresults.cc:47
float Feature
data type for instance predicted label
Definition: types.h:31
void sorted_labels(const Score *scores, Label *dest, const size_t cutoff) const
Sorts the element of the current result list in descending order of the given scores vector and store...
Definition: queryresults.cc:55
size_t num_results() const
Definition: queryresults.h:55
virtual ~QueryResults()
Definition: queryresults.cc:34
double Score
data type for instance truth label
Definition: types.h:30
Label * labels_
Definition: queryresults.h:78
Feature * features_
Definition: queryresults.h:79
Feature * features() const
Definition: queryresults.h:49
QueryResults(size_t n_results, Label *new_labels, Feature *new_features)
Allocates an Query Results Object.
Definition: queryresults.cc:27
This class wraps a set of results for a given query.
Definition: queryresults.h:36
float Label
Definition: types.h:29
size_t num_results_
Definition: queryresults.h:80