-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathranker.h
180 lines (131 loc) · 5.34 KB
/
ranker.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/* ranker.h -*- C++ -*-
Jeremy Barnes, 9 August 2009
Copyright (c) 2009 Jeremy Barnes. All rights reserved.
A ranker for a set of candidates from the GitHub contest. Abstract
interface.
*/
#ifndef __github__ranker_h__
#define __github__ranker_h__
#include "data.h"
#include "candidate_source.h"
#include "utils/configuration.h"
#include "boosting/dense_features.h"
#include "boosting/classifier.h"
// Global variables for statistics; per-thread
extern __thread int correct_repo;
extern __thread const IdSet * watching;
/*****************************************************************************/
/* CANDIDATE_GENERATOR */
/*****************************************************************************/
// Base class for a candidate generator
struct Candidate_Generator {
virtual ~Candidate_Generator();
virtual void configure(const ML::Configuration & config,
const std::string & name);
virtual void init();
virtual boost::shared_ptr<const ML::Dense_Feature_Space>
feature_space() const;
virtual void
features(std::vector<ML::distribution<float> > & result,
int user_id,
const Ranked & candidates,
const Candidate_Data & candidate_data,
const Data & data) const;
/// Generates a set of candidates to be ranked for the given user
virtual void
candidates(Ranked & ranked, Candidate_Data & candidate_data,
const Data & data, int user_id) const;
std::vector<boost::shared_ptr<Candidate_Source> > sources;
std::vector<int> source_num_features;
};
/*****************************************************************************/
/* RANKER */
/*****************************************************************************/
/// Base class for a candidate ranker
struct Ranker {
virtual ~Ranker();
virtual void configure(const ML::Configuration & config,
const std::string & name);
virtual void init(boost::shared_ptr<Candidate_Generator> generator);
virtual boost::shared_ptr<const ML::Dense_Feature_Space>
feature_space() const;
virtual void
features(std::vector<ML::distribution<float> > & result,
int user_id,
const Ranked & candidates,
const Candidate_Data & candidate_data,
const Data & data) const;
virtual void
rank(Ranked & candidates,
int user_id,
const Candidate_Data & candidate_data,
const Data & data) const;
boost::shared_ptr<Candidate_Generator> generator;
};
struct Classifier_Ranker : public Ranker {
virtual ~Classifier_Ranker();
virtual void configure(const ML::Configuration & config,
const std::string & name);
virtual void init(boost::shared_ptr<Candidate_Generator> generator);
virtual boost::shared_ptr<const ML::Dense_Feature_Space>
feature_space() const;
virtual void
features(std::vector<ML::distribution<float> > & result,
int user_id,
const Ranked & candidates,
const Candidate_Data & candidate_data,
const Data & data) const;
virtual void
classify(Ranked & candidates,
int user_id,
const Candidate_Data & candidate_data,
const Data & data,
const std::vector<ML::distribution<float> > & features) const;
virtual void
rank(Ranked & candidates,
int user_id,
const Candidate_Data & candidate_data,
const Data & data) const;
std::string classifier_file;
ML::Classifier classifier;
boost::shared_ptr<const ML::Dense_Feature_Space> ranker_fs;
boost::shared_ptr<const ML::Dense_Feature_Space> classifier_fs;
ML::Dense_Feature_Space::Mapping mapping;
ML::Optimization_Info opt_info;
bool load_data;
};
struct Classifier_Reranker : public Classifier_Ranker {
virtual ~Classifier_Reranker();
virtual void configure(const ML::Configuration & config,
const std::string & name);
virtual void init(boost::shared_ptr<Candidate_Generator> generator);
virtual boost::shared_ptr<const ML::Dense_Feature_Space>
feature_space() const;
virtual void
features(std::vector<ML::distribution<float> > & result,
int user_id,
const Ranked & candidates,
const Candidate_Data & candidate_data,
const Data & data) const;
virtual void
rank(Ranked & candidates,
int user_id,
const Candidate_Data & candidate_data,
const Data & data) const;
virtual void
classify(Ranked & candidates,
int user_id,
const Candidate_Data & candidate_data,
const Data & data,
const std::vector<ML::distribution<float> > & features) const;
Classifier_Ranker phase1;
};
// Factory methods
boost::shared_ptr<Candidate_Generator>
get_candidate_generator(const ML::Configuration & config,
const std::string & name);
boost::shared_ptr<Ranker>
get_ranker(const ML::Configuration & config,
const std::string & name,
boost::shared_ptr<Candidate_Generator> generator);
#endif /* __github__ranker_h__ */