The Kemeny module provides access to the implementation of Kemeny Optimal Aggregation of FLAGR. It is stressed out that due to the method's high complexity, the brute force implementation becomes infeasible even when the number of elements, or the number of input lists receive moderate values.

Implementation file
pyflagr/pyflagr/Kemeny.py

The KemenyOptimal class
The KemenyOptimal class derives from RAM, a base class defined in the RAM module. It inherits the flagr_lib connector from RAM, and through it, it obtains access to the FLAGR shared library. Its constructor determines the data types of the input arguments and the return type of the FLAGR's Kemeny exposed function. Observe the similarity between the members of self.flagr_lib.Kemeny.argtypes and the input arguments of the Kemeny exposed function.

The arguments of the constructor includes one parameter:

Parameter Type Default Description
eval_pts Integer, Optional. Considered only if rels_file or rels_df is set. 10 Determines the elements in the aggregate list on which the evaluation measures (i.e. Precision, and nDCG) will be computed. For example, for eval_pts=10 FLAGR will compute Average Precision, \(P@1, P@2, ... P@10\) and \(N@1, N@2, ... N@10\).


KemenyOptimal also includes an aggregate() function which receives the user-defined parameters and passes them to the Kemeny exposed function, that subsequently performs the aggregation of the ranked input preference lists. The arguments of aggregate() are:

Parameter Type Default Description
input_file String - Required, unless input_df is set. Empty String A CSV file that contains the input lists to be aggregated.
input_df Pandas DataFrame - Required, unless input_file is set. None A Pandas DataFrame that contains the input lists to be aggregated.
Note: If both input_file and input_df are set, only the former is used; the latter is ignored.
rels_file String, Optional. Empty String A CSV file that contains the relevance judgements of the involved list elements. If such a file is passed, FLAGR will evaluate the generated aggregate list/s by computing several retrieval effectiveness evaluation measures. The results of the evaluation will be stored in the eval_df DataFrame. Otherwise, no evaluation will take place and eval_df will be empty.
rels_df Pandas DataFrame, Optional. None A Pandas DataFrame that contains the relevance judgements of the involved list elements. If such a dataframe is passed, FLAGR will evaluate the generated aggregate list/s by computing several retrieval effectiveness evaluation measures. The results of the evaluation will be stored in the eval_df DataFrame. Otherwise, no evaluation will take place and eval_df will be empty.
Note: If both rels_file and rels_df are set, only the former is used; the latter is ignored.
output_dir String, Optional. Temporary directory (OS-specific) The directory where the output files (aggregate lists and evaluation) will be stored. If it is not set, the default location will be used.

The following interactive block diagram depicts the architecture of PyFLAGR and its linkage to the FLAGR shared library.

PyFLAGR architecture