The Importance of Parameters in Ranking Functions
Abstract
How important is the weight of a given column in determining the ranking of tuples in a table? To address such an explanation question about a ranking function, we investigate the computation of SHAP scores for column weights, adopting a recent framework by Grohe et al. [ICDT’24]. The exact definition of this score depends on three key components: (1) the ranking function in use, (2) an effect function that quantifies the impact of using alternative weights on the ranking, and (3) an underlying weight distribution. We analyze the computational complexity of different instantiations of this framework for a range of fundamental ranking and effect functions, focusing on probabilistically independent finite distributions for individual columns.
For the ranking functions, we examine lexicographic orders and score-based orders defined by the summation, minimum, and maximum functions. For the effect functions, we consider global, top-, and local perspectives: global measures quantify the divergence between the perturbed and original rankings, top- measures inspect the change in the set of top- answers, and local measures capture the impact on an individual tuple of interest. Although all cases admit an additive fully polynomial-time randomized approximation scheme (FPRAS), we establish the complexity of exact computation, identifying which cases are solvable in polynomial time and which are #P-hard. We further show that all complexity results, lower bounds and upper bounds, extend to a related task of computing the Shapley value of whole columns (regardless of their weight).
Keywords and phrases:
Ranking, Explanation, Shapley value, SHAP scoresFunding:
Christoph Standke: ERC grant 101054974 (SymSim) and German Research Foundation grant GRK 2236 (UnRAVeL). Views and opinions expressed are however those of the author(s) only and do not necessarily reflect those of the European Union or the European Research Council. Neither the European Union nor the granting authority can be held responsible for them.Copyright and License:
2012 ACM Subject Classification:
Information systems Retrieval models and rankingAcknowledgements:
This work has been initiated in Dagstuhl Seminar 24032: Representation, Provenance, and Explanations in Database Theory and Logic.Editors:
Balder ten Cate and Maurice FunkSeries and Publisher:
Leibniz International Proceedings in Informatics, Schloss Dagstuhl – Leibniz-Zentrum für Informatik
1 Introduction
A ranking function takes as input a set of records and produces a permutation over the set based on the entry values (commonly referred to as features) of the records. As ranking is abundant in decision making, it is natural to look for an explanation for the outcome of the ranking of a given dataset. Explanations for ranking functions have received significant attention in the area of Information Retrieval (IR) over recent years [25, 24, 32, 38] and before, as well described in surveys on “explainable IR” [30, 2]. Explanations for ranking can be largely categorized into two types: A value-based explanation aims to elucidate how the values of a certain record led to its being ranked in its position (or why it is included in, or excluded from, the top- answers); this is typically done by quantifying the contribution of every entry value to the status of the record [1, 9, 25]. On the other hand, a function-based explanation aims to investigate what aspect in the ranking function has led to the outcome, from the point of view of a specific record or the entire permutation; this is typically done by quantifying the contribution of function components to the outcome [37, 14, 19, 32]. This work belongs to the latter kind.
Typically, the ranking function involves parameters. For example, if the ranking is determined by a score function that is a linear combination of the attributes of the record, then the parameters are the weights attached to the features of the record. Previous work in the database community has investigated ways of selecting parameters so that the ranking function satisfies certain criteria [4, 8]. In this work, we study the contribution of the parameter choices to the outcome of the ranking. For that, we adopt the framework of Grohe et al. [18] for measuring the importance of parameters in the context of database queries, where the contribution of a parameter is determined by its SHAP score [23]. In contrast to previous work on the explanation of ranking functions, we focus on the computational complexity of calculating the contribution.
SHAP scores and Shapley values.
The SHAP score [23] is an instantiation of the Shapley value that, in turn, is used to attribute a share to each player in a cooperative game, where each coalition (set of players) gains some utility [31]. The Shapley value, named after its inventor, is unique up to some axioms of rationality (e.g., the sum of shares adds up to the utility of the entire set) [31, 28] and, besides applications in a plethora of domains, has been used for explanations in data-centric fields such as Machine Learning [23, 11, 29], IR [9, 19], and databases [21, 6, 10]. The SHAP score was originally proposed for the purpose of explaining machine-learned models, and particularly attributing responsibility for the outcome of the model to the feature values of a particular instance [23, 20].
Specifically, SHAP is the Shapley value in the cooperative game where the feature values are the players, and the utility of a coalition is the expected effect (model’s output) of the instance where the feature values of are used and the rest chosen randomly. In the framework of Grohe et al. [18], the parameter values play the same role that feature values play in the application of SHAP to machine-learning explanations [23, 20] and that feature values play in the application of SHAP to value-based explanations of ranking [26, 9]. Moreover, the Shapley value has recently been used in function-based explanations [19].
Connecting to this work, consider a particular parameterized ranking function, along with a particular choice of values for its parameters. These define a ranking over the given a set of records. To apply the SHAP score, two additional components need to be determined. The first is a distribution from which parameter choices are assumed to be drawn. The second is an effect function that determines how different the ranking obtained from a specific (random) choice of parameters is from the base ranking with the original choice of parameters. The effect function captures different interpretations of what Heuss et al. [19] refer to as “listwise feature attribution.” Similarly to the study of Grohe et al. [18], we restrict the discussion to simple distributions of parameters, namely finite and probabilistically independent parameters (i.e., “fully factorized” distributions [36]).
From the computational perspective, the SHAP score entails an expectation (w.r.t. a random choice of players) over an expectation (over the random parameter choices). Nevertheless, it was shown by Grohe et al. [18] that the SHAP score can also be viewed as a single expectation over an efficiently samplable space; therefore, the SHAP score of a parameter can be computed in polynomial time via sampling if we settle for a randomized additive approximation (FPRAS), under the mild assumption that the effect function is computable in polynomial time. This technique allows additive approximations also for more general classes of probability distributions, including fully factorized continuous distributions that allow efficient sampling. Moreover, if we make a data complexity assumption of a fixed number of parameters, then the SHAP score can be computed in polynomial time via an explicit enumeration of the probability space. We investigate the ability to compute the SHAP score exactly (and deterministically), for a given (non-fixed) number of parameters, in polynomial time. Van den Broeck et al. [36] have established that there are polynomial-time reductions in both directions between the computation of the SHAP score and the computation of the expected effect, which is arguably a simpler notion. Hence, following their result, we focus mainly on the expected effect throughout the paper.
Studied ranking and effect functions.
Our study considers a variety of basic ranking functions and effect functions. For ranking, we consider the score functions of , , and , and the lexicographic ordering (descending or ascending). In all of these functions, the parameters are coefficients (weights) over the record attributes. We view the dataset simply as a matrix (where every row corresponds to a record), and the parameters as per-column multiplicative weights. For the effects, we consider three types: global measures determine an effect over the entire ranking, top- measures determine the impact on the set of top- answers, and local measures determine the impact on a single record. The global measures we consider are standard distances between permutations [27, 5], and specifically Kendall’s tau, maximum displacement, and Hamming distances between the random ranking (due to the random choice of parameters) and the base ranking. The top- measures include the symmetric difference between the top- sets (for the base and random rankings) and the binary indicator of whether there is any difference between the top- sets. The local measures include the change in the record’s position and the change in its status of membership in the set of top- answers. A detailed example is presented at the end of Section 3.
Contributions.
We begin with algorithms for a simpler task: given two records and , compute the probability (for randomly chosen parameters) that precedes in the ranking. This problem is tractable for all the ranking functions we consider, while for we make the necessary assumption that the numbers are in unary representation (as the problem is FP#P-hard111Recall that FP#P is the class of functions computable in polynomial time using an oracle to some function in #P. A function is FP#P-hard if there is a polynomial-time Turing reduction from every function in FP#P to . Such a problem is at least as hard as every problem in the polynomial hierarchy [34]. for the binary representation). Our results (summarized in Table 1) show that, in general, this pairwise case suffices for the tractability of some of the effect functions, namely Kendall’s tau and the position and top- membership of a row for small ; for the rest, we prove hardness results. We also consider the case where the number of records is bounded, thus, we have a small number of competitors. There, we prove that all problems become tractable, again with the exception of with binary numeric representation.
Finally, we consider another variation of a function-based explanation for ranking, now parameter-free. The goal is to compute the contribution of whole columns (attributes) to the ranking. More precisely, we consider the Shapley value of the cooperative game where the players are the columns, and the utility of a set of columns is the effect of the ranking obtained by considering only the columns in the set, while ignoring the rest. This task has been presented by Heuss et al. [19] where they refer to the action of ignoring a column as “masking the feature vector,” yet with no complexity analysis. We show that this problem reduces in polynomial time to the problem in the focus of this paper, namely computing the SHAP score of parameter choices. Hence, our algorithms for the SHAP score of parameters can be used for the Shapley value of columns. Moreover, we show that the hard cases of computing the SHAP scores are hard already for the Shapley value of columns.
Organization.
We begin with preliminary definitions in the next section. In Section 3, we describe the formal framework and computational problems that we study, namely the SHAP score of parameters, the expected effect, and the Shapley value of columns. We give algorithms for the expectation in Section 4 and establish lower bounds in Section 5. Finally, we discuss extensions to the Shapley value of columns in Section 6, and conclude in Section 7. For space limitations, some of the proofs are given in the archive version of this paper [33].
| Global | Local | ||||
| Top- membership | |||||
| Kendall’s | MD | Position | Fixed | Given | |
| unary | P | FP#P-h. | P | FP#P-h. | FP#P-h. |
| binary | FP#P-h. | FP#P-h. | FP#P-h. | ||
| / | P | FP#P-h. | P | FP#P-h. | FP#P-h. |
| / | P | P | P | ||
| Lexicographic | P | P | FP#P-h. | ||
2 Preliminaries
We begin with preliminary concepts and terminology that we use throughout the paper.
Matrices and permutations.
For a natural number , we denote by the set , and by the set of permutations over (i.e., bijective functions ). By we denote the identity permutation defined by for all . By we denote the set of all permutations, that is, . We denote by the set of all matrices, over the rational numbers, with rows and columns, and by the set of all matrices of all dimensions (i.e., ). If and represents a set of columns, then we denote by the matrix obtained from by removing all columns except those in . In other words, is the projection of on under bag semantics. We may refer to a row of a matrix as a tuple. We denote such a row (and every numeric vector) in boldface and its th entry with .
Computation-wise, we assume every number is represented as a pair , standing for the rational number , where and are integers in a binary representation. When we refer to a unary representation, we mean an integer encoded as a string of length .
Ranking functions.
By a ranking function we refer to a function that maps every matrix to a permutation in ; hence, ranks the rows of its input matrix . Specifically, we will focus on several ranking functions :
-
Ranking by decreasing/increasing score of a row , with the score being the sum of the , denoted , the maximum among the , denoted , or the minimum among the , denoted . For each scoring function , we denote by and the rankings by decreasing and increasing , respectively. For example, we have , meaning that the th row precedes the th row , whenever .
-
Ranking by the lexicographic ordering (left to right) over the rows, denoted .
In our analysis, the direction of the ranking with respect to the score (increasing/decreasing) is important for ranking by and , as shown in Table 1. This direction is not important for ranking by since we can switch between the directions by multiplying the entries by a negative number (or subtracting each value from the maximum value in the matrix); hence, we simply write as standing for (since is equivalent). In the lexicographic order, we assume for the same reason that the order of each column is ascending (i.e., lower numbers precede higher numbers). Also for the same, we will not consider ranking by explicitly since it is the same as ranking by of the negated matrix in reversed direction.
For the framework to be well-defined, we need to handle tie-breaking. For that, we will use the ordering by the row indices; that is, if the rows and are tied by the ordering and , then we give precedence to the th row.
Shapley value.
A cooperative game is a pair where is a finite set of players and is a utility function that associates with every coalition a value , so that . The Shapley value of a player is defined by the following formula [28, 31].
| (1) |
Intuitively, we consider the situation where we select players iteratively without replacement, starting with the empty set; the Shapley value of a player is the mean increase in utility when adding .
SHAP score.
Let be an -ary function over some domain . Let be a discrete distribution over , and let be a tuple from with a nonzero probability. For , the SHAP score of with respect to (w.r.t.) , denoted , is the value for the cooperative game defined as follows [23].
-
;
-
.
That is, the utility of a subset of parameters is the expectation of over the distribution , conditioned on every parameter in having its specific value from .
3 Framework and Computational Problems
Our goal is to compute the contribution of columns and column weights to the ranking of the rows of a given matrix. For that, we need to reason about how different the ranking would be had we eliminated certain columns or changed their weights. Therefore, we need to adopt a measure of difference between permutations. We refer to such measures as effect functions, as they determine the effect of the column alteration.
Effect functions.
We are given a matrix and a ranking function with original order . As a result of applying the ranking function with different weights on the columns (or only on a subset of columns), we get a different permutation . We will focus on three classes of effect functions:
-
Global perspective: How far is from the original permutation? We can use several notions of distance between permutations. We give here three conventional ones, where the first two were used for ranking explanation in the RankSHAP work [9].
-
–
Kendall’s tau: determines the number of pairwise disagreements (swaps) between and the original order. This effect function has the range .
-
–
Maximum Displacement (MD) distance: is the maximum difference of an item’s position between the two permutations. This difference is a number in .
-
–
Hamming distance: determines the number of positions where the tuple is different between the original and permuted orders. It can attain values in .
-
–
-
Top- perspective: What is the impact on the set of top- answers? For that, let and we will consider two functions.
-
–
Top- difference: is the size of the symmetric difference between the sets of top- elements.
-
–
Top- any-change: determines whether there is any change in the top- elements.
-
–
-
Local perspective: What is the impact on a specific row ? We will consider two functions:
-
–
Position: is the change of position of the th row and is in the range .
-
–
Top- membership: determines how the th row changes its membership in the top- tuples. Its range is either or .
-
–
In the analysis we conduct in the remainder of this paper, we focus on four effects: Kendall’s tau, MD, position, and top- membership. The complexity results for the Hamming distance are the same as those of MD. The complexity results for the impacts of the top- perspective are the same as the top- membership. Details are in the archive version [33].
Computing SHAP scores.
Next, we assume that the columns of the input matrix are weighted, and the goal is to compute the SHAP score of a given weight. To make it precise, we assume that our data is a pair , where and is a sequence of column weights. The pair represents the pair , which is the matrix obtained by multiplying the th column by for ; that is, we apply element-wise multiplication by to each row of , or, in other words, where is the diagonal matrix whose diagonal elements are given by .
We will also assume that, in addition to and , we are given a finite probability distribution over . We restrict our complexity study to column-wise independent distributions (i.e., fully factorized distributions [36]), hence, is represented by finite distributions over for each weight parameter, each distribution given as a list of value-probability-pairs; the total number of such pairs is denoted by .
Let be a ranking function and an effect function. Given the pair and a column number , our goal is to compute , where , that is, the inverse of the effect on the ranking of replacing the weights of with those of . We denote this value by . The reason for the inverse (using minus) is that the closer we are to the original ranking order (i.e., the less effect), the higher we deem the contribution to the the actual in place.
| Problem: | : SHAP score computation |
|---|---|
| Fixed: | Ranking function and effect function |
| Input: | Matrix , weight vector , distribution , and column number of |
| Goal: | Compute |
In this and the other problems we consider, when the effect function is local, the input also includes the row number of the effect. In addition, when is the top- membership, then the input also includes (unless we explicitly state that is assumed to be fixed).
It has been established by Van den Broeck et al. [36] that, for finite and probabilistically independent parameters, calculating the SHAP score is computationally equivalent to calculating the expected value of , which is arguably simpler to handle.
Theorem 1 ([36, Theorem 2]).
Let be a function that can take any number of numerical arguments and can be computed in polynomial time. The following problems are polynomially (Turing) reducible to each other.
-
1.
Compute , given , and .
-
2.
Compute , given and .
Hence, we will also study the following problem.
| Problem: | : Expectation computation |
|---|---|
| Fixed: | Ranking function and effect function |
| Input: | Matrix and distribution |
| Goal: | Compute |
Computing Shapley values.
Let be a ranking function and an effect function. Given a matrix and a column number , the Shapley value of the th column is defined as for the game defined as follows:
-
.
-
, that is, the inverse of the effect on the ranking we obtain by applying to only the columns of (with the same rationale for inverse as SHAP).222The ranking function applied to the empty set of columns always yields the matrix order since all tuples of are identical. In particular, this definition does not depend on the value of the scoring function on the empty set.
We denote this value by .
| Problem: | : Shapley value computation |
|---|---|
| Fixed: | Ranking function and effect function |
| Input: | Matrix and a column number of |
| Goal: | Compute |
Approximation.
Before moving to exact algorithms, we want to emphasize that each of the three problems , , and can be efficiently additively approximated whenever and can be computed in polynomial time and the range of is polynomial in the number of rows. This is the case for all ranking and effect functions introduced in this section. As we will show in Section 5.2, this is not always the case for multiplicative approximations. The additive approximation can be done via basic Monte-Carlo-sampling since all three problems can be expressed as the expectation of a random variable over a probability space that allows efficient sampling: for , for , and for . We can use this insight for efficient additive approximations also in the case of not necessarily independent discrete parameter distributions under very mild assumptions (see [18]) or independent continuous parameter distributions that can be sampled efficiently.333For continuous distributions, the definition of the SHAP score via conditional representations is not well-defined since the set we condition on has measure . In the case of independent distributions, we can derive a compatible definition via disintegration, that is, fixing the parameters in to their reference values and choosing the others at random. This simple idea was further improved to allow for faster additive approximations (e.g. [7]). Hence, our framework could be applied in practice, even in cases where we show that exact computation is hard.
A detailed example.
Before we start our complexity analysis, let us first look at a small example that demonstrates the framework in detail. Consider the following matrix :
| id | ||
|---|---|---|
| 1 | 20 | 26 |
| 2 | 30 | 13 |
| 3 | 40 | 0 |
| 4 | 0 | 39 |
Assume that we rank the row by in descending order with a scoring parameter . We want to measure the impact of choosing the weight vector among the possible choices for (where we assume a uniform distribution).
To measure this, we first determine the rankings for each : For , the scores are , so we obtain the ranking . In the same way, we obtain for , for , and again for .
| scores | permutation | |||
|---|---|---|---|---|
| (46,43,40,39) | 0 | 4 | ||
| (72,56,40,78) | 3 | 1 | ||
| (66,73,80,39) | 3 | 4 | ||
| (92,86,80,78) | 0 | 4 |
Now, we need to choose an effect function that measures the distance between two rankings. We will look at the Kendall’s tau distance and the position of the fourth row . We observe that and that the row is in the last position of all the rankings except for where it is first.
For the SHAP score calculation, the valuation of a set of columns is the expected value of the negated effect function when we fix the parameter value for the columns in to the value of and choose the rest at random. For example, for , we obtain for
and for , we obtain . Calculating the valuation of every gives the following. For , we obtain and as well, so both parameter choices have the same impact w.r.t. global changes in the ranking measured by . This reflects the symmetry in the 4th column of table above. In contrast, for , we obtain and . This matches our intuition that fixing the second weight to is bad for the ranking of row , since the only good weighting vector for row is .
In the remainder of the paper, we study the complexity of exactly solving the computational problems we defined in this section.
4 Exact Algorithms for Expectation (and SHAP Scores)
In this section, we show the tractability results of Table 1 for – computing the expected effect. Combined with Theorem 1, these give the tractability results of the table for the SHAP score. We begin a more basic problem that we later use for expectation.
4.1 Algorithms for the Pairwise Case
We begin with the following problem: Given tuples and , what is the probability that precedes in the ranking? Since we only care about their relative order, we can ignore all the other tuples in the table and assume . Although this pairwise case may seem highly restricted, we will see in the next section that it forms the foundation of all our algorithms.
| Problem: | : Precedence probability computation |
|---|---|
| Fixed: | Ranking function |
| Input: | Matrix with two rows, distribution |
| Goal: | Compute where stands for |
A naive way to compute the probability of precedence is to iterate through the exponentially many choices of weights and check whether tuple precedence holds in the resulting order. We exploit the fact that many of these choices can be grouped together, allowing us to consider only a polynomial number of possibilities. This can be achieved for all ranking functions discussed in this paper, except for where our algorithm is pseudo-polynomial, that is, polynomial in the magnitude of the given values.
Theorem 2.
The problems , , and are solvable in polynomial time. The problem is solvable in polynomial time if the matrix and the weights in are integers encoded in unary.
We now give the algorithm for each ranking function in Theorem 2. For readability, we use and for the two tuples and in the matrix. Our goal is to compute the probability that precedes ; without loss of generality, we assume that this is false in the event of a tie.
Sum ranking.
For , our algorithm relies on dynamic programming and follows a similar approach to the standard pseudo-polynomial algorithm for the counting knapsack problem [16]. Specifically, we consider a subproblem where the matrix is restricted to columns and compute the probability that tuple surpasses tuple by (strictly) more than in total score. This can be expressed recursively by considering how the score difference changes when removing the -th column for each assignment to the weight :
| (2) | |||
| (3) |
The final answer is . The running time is where is the number of possible values for in our dynamic program. If the input consists of integers given in unary, then is polynomial in the input size. Indeed, suppose the matrix contains integers in the range and the weights in are in the range . Then will be bounded by , which is in .
Max ranking.
For the ranking function, the key idea is that the “winner” in the comparison between the two tuples is determined by a single column – the one with the maximum value. Thus, we can break the problem into distinct cases, each corresponding to a specific column determining the outcome.
Example 3.
Let and be two tuples, and suppose that the weights are drawn uniformly from , and the ranking function is . For to be ranked before , we need . We consider three distinct cases where this event occurs: (Case 1) The first -coordinate is the overall maximum. We iterate over possible values of , and for each one, we determine the valid weights for and individually. If , then cannot be the winner. If , then the valid sets of weights are: , , . This occurs with probability . (Case 2) The second -coordinate is the overall maximum. This cannot happen. (Case 3) The third -coordinate is the overall maximum. Here, we obtain the sets , , . All combinations of these weights are valid, thus the probability is . Summing up the probabilities from the valid cases, we obtain the final result .
Algorithm 1 builds on the logic of our example, decomposing the comparison of two maximum predicates into distinct cases, and computing their probabilities efficiently. Some care is required in the event of ties among columns of ; in such cases, we elect the first occurring maximum to be the winner, ensuring that the cases remain distinct. The decomposition can be expressed as follows:
| (4) | |||
| (5) | |||
The algorithm constructs these distinct events and for each one, it determines sets of valid weights for , except for position where the weight has been fixed to . Finally, the probability of these events is computed efficiently, since the distributions are independent. The running time of the algorithm is .
Lexicographic ranking.
We now move on to ranking by lexicographic orders. Our algorithm again follows a decomposition into non-overlapping events, each corresponding to a specific column and its weight determining the outcome. For this to happen, all preceding columns need to be tied between the two tuples. The decomposition works as follows:
| (6) | |||
| (7) |
Similarly to the case of , we construct these events, determine the valid weight assignments for each one, and calculate their probability. The running time is .
Recovering the satisfying weights.
In some cases, we need not only the probability that tuple is before tuple , but also a succinct representation of the weights for which this is true. Fortunately, our decomposition-based algorithms for and provide this directly. We simply need to replace summation with union and multiplication with set product in line 18 of Algorithm 1.
Observation 4.
The algorithms for , , and can additionally return the weights for which precedence holds as a disjoint list, where each element consists of a set of valid weights per column, i.e., .
4.2 From Pairwise Impact to Ranking Impact
We now extend the polynomial-time algorithms for the pairwise case to the expected effect on the overall ranking. When the effect function measures the position of a tuple or Kendall’s tau for the entire permutation, we can reduce the problem to a polynomial number of calls to . For both measures, we can write the expected effect as the expectation of a sum of indicator variables for tuple precedence and then use the linearity of expectation.
Theorem 5.
For ranking function and effect function , the problem is solvable in polynomial time. For ranking function and effect function , the problem is solvable in polynomial time if the matrix and the weights in are integers encoded in unary.
The final case that admits a polynomial-time algorithm is the expected top- membership for fixed and ranking by . Interestingly, our approach only applies to a descending order, and in fact, we prove in the next section that the problem is hard when the order is ascending. The key idea of the algorithm is that, for this specific ranking function, we can compute the probability that the tuple of interest beats a small subset of other tuples.
| 3 | 1 | 0 | |
| 1 | 0 | 4 | |
| 0 | 1 | 1 | |
| 2 | 2 | 2 |
| 3 | 1 | 4 | |
| 2 | 2 | 2 |
Example 6.
Suppose the matrix contains tuples as shown in Figure 1, the ranking function is , and our goal is to compute the probability that is ranked top-1. We can merge the competitor tuples into a single competitor that retains the largest value per column. Now, is top-1 precisely when it precedes in the ranking. This merging has effectively reduced the problem to the pairwise problem , which we have already established can be solved efficiently.
The example illustrates how the algorithm works when . For , we apply the principle of inclusion-exclusion to express the event that our tuple is in the top- as the intersection of events where it ranks above specific subsets of other tuples.
Theorem 7.
The problem with as a fixed parameter is solvable in polynomial time.
Later, we will show that the assumption of a fixed is necessary since the problem becomes intractable otherwise (Theorem 12).
4.3 Bounding the Matrix Dimensions
We conclude this section by investigating the consequences of bounding one of the two dimensions of our matrix by a fixed constant. This allows us to obtain a clearer picture of the parameters that make the problem hard. We find that such a restriction makes the problem significantly easier and, in most cases (with the exception of with arbitrary values), both dimensions need to be non-fixed for the problem to be hard.
Theorem 8.
The following hold.
-
1.
If the number of columns of the matrix is bounded by a constant, then the problem is solvable in polynomial time for any ranking function and effect function computable in polynomial time.
-
2.
If the number of rows of is bounded by a constant, then the problem is solvable in polynomial time for any effect function computable in polynomial time and
-
(a)
the ranking function is in , or
-
(b)
is the ranking function and, additionally, the matrix and weights in are integers encoded in unary.
-
(a)
We note that the proof is straightforward for the cases where (the number of columns) is fixed, since we can then materialize the entire probability space in an explicit representation. The proof of tractability for a fixed number of of rows is more involved.
5 Intractable Cases for Expectation (and SHAP Scores)
We now show that the collection of tractability results in Section 4 is complete in the sense that expectation (and SHAP) computations are -hard for all remaining combinations of and .
5.1 Ranking based on Summation
We start with the observation that precedence probability is hard for ranking by .
Theorem 9.
is -hard, if the input matrix is encoded in binary.
The proof of this theorem is given in the archive version [33]. We use the following lemma to prove this claim by reducing from the counting knapsack problem that, given natural numbers and a number all encoded in binary, asks for the number of subsets with . This problem is known to be -hard (see, e.g., [12, 16]).
Lemma 10.
Let and be an input to the counting knapsack problem. Then, there is a matrix with the following property: For each set of columns, we have if and only if contains and .
Proof.
Consider the following matrix :
| id | ||||
|---|---|---|---|---|
| 1 | 0 | 0 | ||
| 2 | 0 |
It is easy to verify this has the claimed property.
We can use this theorem to show the hardness of expectation computation (and hence SHAP score computation) whenever we rank by .
Corollary 11 (from Theorem 9).
For each of the effect functions , the problem is -hard if the input matrix is encoded in binary.
Proof.
We observe that for , expectation computation of the effect functions is equivalent to precedence probability computation, as they are all of the form with .
For , and , we consider a matrix where and , so all the tuples up to are identical. Now, is in the top- of is equivalent to being ranked better than in . This yields the claim.
5.2 Top-k Membership
In Section 4, we saw a polynomial-time algorithm for when is a parameter. We now show that this problem is hard for all other ranking functions we consider.
Theorem 12.
For each ranking function the problem is -hard, when is a parameter and also when is part of the input. Furthermore, is -hard if is part of the input. These claims remain true if the entries of are restricted to and the distribution is the uniform distribution on .
We prove this theorem (in the archive version [33]) using a reduction from counting satisfying assignments to positive CNF formulas. This problem is known to be -hard [35]. Before we continue, we fix some notation for the remainder of this section. Let be Boolean variables. A vector defines an assignment by interpreting as and as . A set defines the assignment , where is the incidence vector of .
Example 13.
We illustrate how the satisfiability of a CNF formula can be modeled using the top-1 membership problem. Let our formula be . We construct the matrix shown in Figure 2, with columns corresponding to formula variables and tuples corresponding to clauses. A value of one indicates that the corresponding variable appears in the clause. Now, let the column weights be , representing whether a variable is or , and let the ranking function be . By our construction, is top-1 if and only if all clauses are satisfied.
We are now ready to state our main tool for the proof of Theorem 12.
| 0 | 0 | 0 | 0 | |
| 1 | 1 | 0 | 1 | |
| 1 | 0 | 1 | 0 | |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 1 | 0 | |
| 0 | 0 | 0 | 0 | |
| 1 | 1 | 0 | 1 | |
| 0 | 1 | 1 | 1 |
Lemma 14.
Let be a positive CNF formula with variable set and clauses . Furthermore, let . Then, there is a matrix with entries in and the following property: For each set of columns and each ranking function , we have if and only if the assignment models .
Remark 15.
Using [3, Corollary 10], the previous lemma directly shows that we cannot approximate SHAP scores for and unless .
5.3 Maximum Displacement Distance
In this section, we prove that expectation computation is a hard problem if we measure the effect using the maximum displacement distance .
Theorem 16.
For and , the problem is -hard. This remains true if the entries of are restricted to and the distribution is the uniform distribution on .
We prove this theorem (in the archive version [33]) via a reduction from counting satisfying assignments to positive CNF formulas. The proof is similar to that of Theorem 12, but with a small twist. Since is a global measure, we cannot define a matrix where we separate satisfying assignments from non-satisfying ones. Instead, we will define two matrices and in a way that the difference of the effect functions allows this distinction.
Lemma 17.
Let be a positive CNF formula with variable set and clauses . Then, there exist two matrices and with entries in and the following property: For each set of columns and each ranking function , we have
| (8) |
Proof sketch of Lemma 17.
The construction of the matrices is similar to Examples 6 and 14 with more copies of the all-zero tuple, which occupy the top positions whenever the formula is satisfied, yielding zero displacement. Matrix contains one additional copy of the all-zero tuple compared to , so the two matrices behave similarly, but the maximum displacement in is higher than that of by exactly 1 whenever the formula is not satisfied.
6 Exact Computation of the Shapley Value
In this section, we turn our attention to the importance of columns via the Shapley value instead of the importance of scoring parameters via the SHAP score. We will first show that all our algorithms from Section 4 for SHAP score computation can be used to determine Shapley values and then complete the picture by extending our results from Section 5.
Theorem 18.
6.1 Algorithms
Gilad et al. [15] give a simple algorithm based on interpolation that computes Shapley values in polynomial time when having access to an oracle to a special instance of SHAP score computation called . Translated into our setting, their result is the following:
Theorem 19 ([15, Theorem 6.15]).
Let be a ranking function and be an effect function with the property that for each set of columns, we have . Then, we can solve in polynomial time with oracle calls to .
While the condition of the theorem is always true for ranking by and , it does not necessarily hold for ranking if contains negative numbers. Fortunately, we can make non-negative by adding the minimal value in to each entry without changing the rankings of each set of columns. Hence, we can use the previous theorem to show that all our algorithms carry other to Shapley value computation.
6.2 Intractable Cases
To show hardness results from Section 5, we reduced the counting knapsack problem (Lemma 10) and the problem of counting satisfying assignments to positive CNF formulas (Lemmas 17 and 14) to SHAP score computation via the equivalence to expectation computation (Theorem 1). Since this equivalence does not hold in general for Shapley value computation, we need an alternative approach to extend our results. Instead, we will define two auxiliary games and show the hardness of Shapley value computation for each of them. The proofs are given in the archive version [33]. They follow the technique that is used for most hardness proofs of Shapley value computation [22, 18]: For a given instance to a game, define a set of related instances and use their Shapley values to count valid knapsack sets or satisfying assignments, respectively, via interpolation.
The first game is the knapsack game: For natural numbers and given in binary, consider the game with player set and valuation function where if and , and otherwise.
Lemma 20.
Shapley value computation for the players of the knapsack game is -hard.
The second game is the positive CNF game: Given a positive CNF formula with variable set , consider the game with player set and valuation function where if , and otherwise.
Lemma 21.
Shapley value computation is -hard for the positive CNF game.
With these lemmas and the constructions from Section 5, we can now easily prove Theorem 18. The details are in the archive version of the paper [33].
7 Conclusions
We studied the computational complexity of measuring the importance of parameter choices in ranking functions. Specifically, we investigated the SHAP score of parameters under a collection of specific (yet basic) ranking functions and effect functions. For that, we studied the complexity of calculating the expected effect over random parameter values, focusing on finite and probabilistically independent distributions. We also studied the related problem of computing the Shapley value of columns for measuring their contribution to the ranking.
We view this work as a first step in the rigorous analysis of the complexity of function-based explanations for rankings. As such, many directions are left for future investigation. We would like to generalize our results into broad classes of ranking and effect functions, rather than considering specific cases separately. In particular, we aim to analyze the implication of the different choices made in popular ranking schemes; examples include sports ranking such as WBSC444https://www.wbsc.org/en/rankings and FIFA/Coca-Cola World Ranking,555https://inside.fifa.com/fifa-world-ranking which have the shape of workflow diagrams with linear combinations of features, and the Computer Science Rankings666https://csrankings.org/ that accounts for a pre-determined choice of publication venues. We also want to extend our analysis to other classes of probability distributions, including uniform distributions over intervals, and to characterize the cases where we can efficiently approximate SHAP multiplicatively. Moreover, we would like to understand the complexity of general types of effect functions that include alternatives to those studied here, such as Spearman’s footrule and the Cayley distance.
Finally, an important direction for future research is to study the practicality of the framework in real-life scenarios, and particularly understand how well the attribution functions of SHAP and Shapley capture people’s intuition on the contribution of the components of a ranking function.
References
- [1] Hadis Anahideh and Nasrin Mohabbati-Kalejahi. Local explanations of global rankings: insights for competitive rankings. IEEE Access, 10:30676–30693, 2022. doi:10.1109/ACCESS.2022.3159245.
- [2] Avishek Anand, Lijun Lyu, Maximilian Idahl, Yumeng Wang, Jonas Wallat, and Zijian Zhang. Explainable information retrieval: A survey, 2022. doi:10.48550/arXiv.2211.02405.
- [3] Marcelo Arenas, Pablo Barcelo, Leopoldo Bertossi, and Mikael Monet. On the complexity of shap-score-based explanations: Tractability via knowledge compilation and non-approximability results. Journal of Machine Learning Research, 24(63):1–58, 2023. URL: http://jmlr.org/papers/v24/21-0389.html.
- [4] Abolfazl Asudeh, H. V. Jagadish, Gerome Miklau, and Julia Stoyanovich. On obtaining stable rankings. PVLDB, 12(3):237–250, 2018. doi:10.14778/3291264.3291269.
- [5] Alexander Barg and Arya Mazumdar. Codes in permutations and error correction for rank modulation. IEEE Trans. Inf. Theory, 56(7):3158–3165, 2010. doi:10.1109/TIT.2010.20484.
- [6] Leopoldo E. Bertossi, Benny Kimelfeld, Ester Livshits, and Mikaël Monet. The Shapley value in database management. SIGMOD Record, 52(2):6–17, 2023. doi:10.1145/3615952.361595.
- [7] Javier Castro, Daniel Gómez, Elisenda Molina, and Juan Tejada. Improving polynomial estimation of the shapley value by stratified random sampling with optimum allocation. Computers & Operations Research, 82:180–188, 2017. doi:10.1016/j.cor.2017.01.019.
- [8] Zixuan Chen, Panagiotis Manolios, and Mirek Riedewald. Why not yet: Fixing a top-k ranking that is not fair to individuals. PVLDB, 16(9):2377–2390, 2023. doi:10.14778/3598581.3598606.
- [9] Tanya Chowdhury, Yair Zick, and James Allan. RankSHAP: Shapley value based feature attributions for learning to rank. In ICLR, 2025. URL: https://openreview.net/forum?id=4011PUI9vm.
- [10] Daniel Deutch, Nave Frost, Benny Kimelfeld, and Mikaël Monet. Computing the Shapley value of facts in query answering. In SIGMOD, pages 1570–1583. ACM, 2022. doi:10.1145/3514221.3517912.
- [11] Alexandre Duval and Fragkiskos D. Malliaros. GraphSVX: Shapley value explanations for graph neural networks. In ECML/PKDD (2), volume 12976 of LNCS, pages 302–318. Springer, 2021. doi:10.1007/978-3-030-86520-7_19.
- [12] Martin E. Dyer, Alan M. Frieze, Ravi Kannan, Ajai Kapoor, Ljubomir Perkovic, and Umesh V. Vazirani. A mildly exponential time algorithm for approximating the number of solutions to a multidimensional knapsack problem. Comb. Probab. Comput., 2:271–284, 1993. doi:10.1017/S0963548300000675.
- [13] Ronald Fagin, Benny Kimelfeld, and Phokion G. Kolaitis. Probabilistic data exchange. J. ACM, 58(4):15:1–15:55, 2011. doi:10.1145/1989727.1989729.
- [14] Abraham Gale and Amélie Marian. Explaining monotonic ranking functions. PVLDB, 14(4):640–652, 2020. doi:10.14778/3436905.3436922.
- [15] Amir Gilad, Martin Grohe, Benny Kimelfeld, Peter Lindner, and Christoph Standke. The importance of parameters in database queries, 2024. doi:10.48550/arXiv.2401.04606.
- [16] Parikshit Gopalan, Adam Klivans, Raghu Meka, Daniel Štefankovic, Santosh Vempala, and Eric Vigoda. An FPTAS for #knapsack and related counting problems. In FOCS, pages 817–826, 2011. doi:10.1109/FOCS.2011.32.
- [17] Erich Grädel, Yuri Gurevich, and Colin Hirsch. The complexity of query reliability. In PODS, pages 227–234. ACM Press, 1998. doi:10.1145/275487.29512.
- [18] Martin Grohe, Benny Kimelfeld, Peter Lindner, and Christoph Standke. The importance of parameters in database queries. In ICDT, volume 290 of LIPIcs, pages 14:1–14:17. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2024. doi:10.4230/LIPIcs.ICDT.2024.14.
- [19] Maria Heuss, Maarten de Rijke, and Avishek Anand. RankingSHAP - listwise feature attribution explanations for ranking models, 2024. doi:10.48550/arXiv.2403.16085.
- [20] Uday Kamath and John Liu. Explainable Artificial Intelligence: An Introduction to Interpretable Machine Learning. Springer, 2021. doi:10.1007/978-3-030-83356-5.
- [21] Ahmet Kara, Dan Olteanu, and Dan Suciu. From Shapley value to model counting and back. PACMMOD, 2(2):79, 2024. doi:10.1145/3651142.
- [22] Ester Livshits, Leopoldo E. Bertossi, Benny Kimelfeld, and Moshe Sebag. The shapley value of tuples in query answering. Log. Methods Comput. Sci., 17(3), 2021. doi:10.46298/LMCS-17(3:22)2021.
- [23] Scott M. Lundberg and Su-In Lee. A unified approach to interpreting model predictions. In NIPS, pages 4765–4774, 2017. URL: https://proceedings.neurips.cc/paper/2017/hash/8a20a8621978632d76c43dfd28b67767-Abstract.html.
- [24] Lijun Lyu and Avishek Anand. Listwise explanations for ranking models using multiple explainers. In ECIR, volume 13980 of LNCS, pages 653–668. Springer, 2023. doi:10.1007/978-3-031-28244-7_41.
- [25] Gustavo Penha, Eyal Krikon, and Vanessa Murdock. Pairwise review-based explanations for voice product search. In CHIIR, pages 300–304. ACM, 2022. doi:10.1145/3498366.350582.
- [26] Venetia Pliatsika, Joao Fonseca, Kateryna Akhynko, Ivan Shevchenko, and Julia Stoyanovich. ShaRP: A novel feature importance framework for ranking, 2024. arXiv:2401.16744.
- [27] Ariel D. Procaccia, Nisarg Shah, and Yair Zick. Voting rules as error-correcting codes. Artificial Intelligence, 231:1–16, 2016. doi:10.1016/j.artint.2015.10.003.
- [28] Alvin E. Roth, editor. The Shapley value : essays in honor of Lloyd S. Shapley. Cambridge University Press, 1988. URL: http://www.loc.gov/catdir/samples/cam031/88002983.html.
- [29] Benedek Rozemberczki, Lauren Watson, Péter Bayer, Hao-Tsung Yang, Olivér Kiss, Sebastian Nilsson, and Rik Sarkar. The Shapley value in machine learning. In IJCAI, pages 5572–5579, 2022. doi:10.24963/ijcai.2022/778.
- [30] Sourav Saha, Debapriyo Majumdar, and Mandar Mitra. Explainability of text processing and retrieval methods: A critical survey, 2022. doi:10.48550/arXiv.2212.07126.
- [31] Lloyd S Shapley. A value for n-person games. In Harold W. Kuhn and Albert W. Tucker, editors, Contributions to the Theory of Games II, pages 307–317. Princeton University Press, Princeton, 1953. doi:10.1515/9781400829156-012.
- [32] Jaspreet Singh and Avishek Anand. Model agnostic interpretability of rankers via intent modelling. In FAT*, pages 618–628. ACM, 2020. doi:10.1145/3351095.33752.
- [33] Christoph Standke, Nikolaos Tziavelis, Wolfgang Gatterbauer, and Benny Kimelfeld. The importance of parameters in ranking functions, 2026. arXiv:2601.06001.
- [34] Seinosuke Toda and Mitsunori Ogiwara. Counting classes are at least as hard as the polynomial-time hierarchy. SIAM J. Comput., 21(2):316–328, 1992. doi:10.1137/0221023.
- [35] Leslie G Valiant. The complexity of enumeration and reliability problems. SIAM Journal on Computing, 8(3):410–421, 1979. doi:10.1137/0208032.
- [36] Guy Van den Broeck, Anton Lykov, Maximilian Schleich, and Dan Suciu. On the tractability of SHAP explanations. Journal of Artificial Intelligence Research, 74:851–886, June 2022. doi:10.1613/jair.1.13283.
- [37] Ke Yang, Julia Stoyanovich, Abolfazl Asudeh, Bill Howe, HV Jagadish, and Gerome Miklau. A nutritional label for rankings. In SIGMOD, pages 1773–1776, 2018. doi:10.1145/3183713.319356.
- [38] Puxuan Yu, Razieh Rahimi, and James Allan. Towards explainable search results: A listwise explanation generator. In SIGIR, pages 669–680. ACM, 2022. doi:10.1145/3477495.3532067.
