Add the implementation of SDBN clickmodel
[xapian.git] / xapian-applications / omega / clickmodel / simplifieddbn.h
blobfac650a42938b129a13589b2c35780f7061a86b4
1 /** @file simplifieddbn.h
2 * @brief SimplifiedDBN class - the Simplified DBN click model.
3 */
4 /* Copyright (C) 2017 Vivek Pal
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifndef OMEGA_INCLUDED_SIMPLIFIEDDBN_H
22 #define OMEGA_INCLUDED_SIMPLIFIEDDBN_H
24 #include <map>
25 #include <string>
26 #include <utility>
27 #include <vector>
29 #include "session.h"
31 enum {
32 PARAM_ATTR_PROB,
33 PARAM_SAT_PROB,
34 PARAM_COUNT_
37 /**
38 * SimplifiedDBN class implementing the SDBN click model.
40 * For more information of DBN click model, see the following paper:
42 * Olivier Chapelle and Ya Zhang. 2009. A dynamic bayesian network click
43 * model for web search ranking. In Proceedings of the 18th international
44 * conference on World wide web (WWW '09).
46 class SimplifiedDBN {
47 /// Relevances of documents corresponding to a query in a search session.
48 std::map<std::string, std::map<std::string, std::map<int, double>>>
49 doc_relevances;
50 public:
51 /// Return the name of the click model.
52 std::string name();
54 /** Builds search sessions from the input log file and returns a list
55 * of generated sessions. Each session contains three values: queryid,
56 * a list of documents in the search result and a list of count of clicks
57 * made on each document in the search result.
59 * @param logfile Path to the final log file.
61 std::vector<Session> build_sessions(const std::string &logfile);
63 /** Trains the model i.e. learning the values of attractiveness
64 * and satisfactoriness parameters modelled by the click model.
66 * @param sessions List of all sessions.
68 void train(const std::vector<Session> &sessions);
70 /** Return predicted relevance of each document in a session i.e. the
71 * estimations of the relevance of each document in a given session based
72 * on a trained model. Values ranging from 0.0 to 1.0.
74 * @param sessions Session class object representing a session.
76 std::vector<std::pair<std::string, double>>
77 get_predicted_relevances(const Session &session);
80 #endif // OMEGA_INCLUDED_SIMPLIFIEDDBN_H