{'fraction_non_alphanumeric': 0.0488278663193678, 'fraction_numerical': 0.01690874575073948, 'mean_word_length': 3.9610162067455104, 'pattern_counts': {'":': 0, '<': 1, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Positivity and Transportation

We prove in this paper that the weighted volume of the set of integral transportation matrices between two integral histograms r and c of equal sum is a positive definite kernel of r and c when the set of considered weights forms a positive definite matrix. The computation of this quantity, despite being the subject of a significant research effort in algebraic statistics, remains an intractable challenge for histograms of even modest dimensions. We propose an alternative kernel which, rather than considering all matrices of the transportation polytope, only focuses on a sub-sample of its vertices known as its Northwestern corner solutions. The resulting kernel is positive definite and can be computed with a number of operations O(R^2d) that grows linearly in the complexity of the dimension d, where R^2, the total amount of sampled vertices, is a parameter that controls the complexity of the kernel.


Introduction
Suppose that among 30 students in a classroom, 7 and 23 have light and dark colored eyes respectively. You are also told that 12 of them have light hair while 18 have dark hair. What are all the possible populations of the 4 subgroups of students with light/light, dark/dark, light/dark and dark/light eyes and hair color respectively? Such quantities can be arranged in a 2 × 2 matrix whose row sum vector must be equal to [7,23] T and column sum vector must be equal to [12,18], [ 3 4 9 14 ] for instance, and more generally any integer values in the dots below that satisfy these constraints: 12 18 7 • • 23 • • Alternatively, suppose that two bakeries in a small village produce daily 7 and 23 loafs of bread each, while two restaurants in the same area each need 12 and 18 loafs to serve their customers every day. What are all the possible morning delivery plans of bread loafs that the two bakeries and shops can agree upon? These seemingly trivial sets of matrices coincide, and are known in the statistics and optimization literature as the sets of contingency tables and transportation plans respectively.
In statistics, the problem of enumerating all such tables arises naturally in hypothesis testing. Suppose that by entering the aforementioned classroom you observe that the actual repartition of these groups is [ 5 2 7 16 ]. Such an observation intuitively suggests that eye and hair color are related, but how confident should you be about this statement? In the 2 × 2 case presented above, the Fisher exact test (Yates, 1934) answers that question by computing the probabilities of all possible tables outcomes if one assumes that they have been generated as the product of independent Bernoulli variables with law p 1 = 7/30 and p 2 = 12/30. By comparing all these probabilities with that of the observed table, we can conclude how reliable an independence hypothesis would be. In optimization, given a 2 × 2 cost matrix which describes the cost (in gas, calories or time) of bringing a loaf from each bakery to each shop, finding the delivery plan with minimal cost is known as a transportation problem. Transportation problems are an extremely general class of linear programs which are known to encompass all instances of network flows (Bertsimas and Tsitsiklis, 1997, p.274).
Optimal transportation distances (Rachev and Rüschendorf, 1998;Villani, 2009) are distances between probability densities which combine both perspectives outlined above, where the probabilistic view on contingency tables is matched with the goal of computing an optimal transportation plan between two marginal probabilities given a metric on the probability space of interest. Such distances have been widely used in computer vision following the impulsion of Rubner et al. (1997) who used it to compare histograms of image features. When used in information retrieval tasks, transportation distances fare usually better in practice than other classical distances for histograms (Pele and Werman, 2009).
Transportation distances have however two notable drawbacks. First, from a geometric point of view, transportation distances are deficient in the sense that they are not negative definite nor Hilbertian. Negative definiteness carries many favorable properties, among which the possibility to create Euclidean embeddings from which the metric can be accurately recovered, as well as the possibility to turn the distance into a positive definite kernel by simple exponentiation, as a radial basis function. Because of this deficiency, there is no known positive definite counterpart to transportation distances that can leverage the complexity of the set of contingency tables. Second, from a computational point of view, the computational cost of computing transportation distances grows in most cases of interest at least quadratically in the dimension d of the histograms, which can be prohibitive for many applications.
We try to address both issues in this work. The main contribution of this paper is theoretical: after providing some background material and motivation in Section 2 we prove in Section 3 that the generating function of the set of all contingency tables between two integral histograms is a positive definite kernel. Our second contribution is practical: we propose in Section 4 a positive definite kernel that leverages these ideas while still being computationally tractable.

Background
2.1. The Transportation Polytope and the Set of Contingency Tables. We review in this section a few definitions, notations and results of interest to prove our result. In the following, we write · , · for both the Frobenius dot-product and the usual dot-product of vectors.
Given a dimension d fixed throughout this paper, for two vectors r, c ∈ R d , let U (r, c) be the transportation polytope of r and c, namely the subset of nonnegative matrices in R d×d defined as: where 1 d is the d dimensional vector of ones. U (r, c) contains all nonnegative d × d matrices with row and column sums r and c respectively. It is easy to check that U (r, c) is non-empty if and only if all coordinates of r and c are non-negative and if the total masses of r and c are the same, that is r T 1 d = c T 1 d . We will consider in most of this work integral vectors r and c taken in the set Σ N of d-dimensional integral histograms with total mass N ∈ N, We will also focus accordingly on the subset U(r, c) of U (r, c) that contains all integral transportation matrices, alternatively known as contingency tables (Lauritzen, 1982;Everitt, 1992):

Weighted Volumes of Contingency Tables and Particular Cases of
Positivity. Ranging from early work by Yates (1934); Good (1976) to Diaconis and Efron (1985); Cryan and Dyer (2003); Chen et al. (2005), the computation of elementary statistics about U(r, c) has attracted considerable attention. Many of the ideas of this paper build upon recent work by Barvinok, most notably on his study of the generating function of U(r, c), defined for M ∈ R d×d as The generating function can be related to the weighted volume (Barvinok, 2008, p.2) of U(r, c), defined for any nonnegative d × d matrix K ∈ R d×d + as: Both definitions are equivalent since if we agree that k ij = e −mij then T (r, c ; K) = V (r, c ; M ). Because all of our results rely on K's properties, we will mostly use the weighted volume formulation in this paper. Some sections in this paper, notably §2.3 below and §4, are better understood with the generating function formulation. Cuturi (2007, Prop.2) proved that the cardinal of the set U(r, c) is a positive definite kernel of r and c using the Robinson-Schensted-Knuth bijection (Knuth, 1970) that maps each contigency table to a pair of Young tableaux with contents r and c and the same pattern. It is easy to see that the cardinal of U(r, c) is equal to T (r, c; 1 d×d ) or V (r, c ; 0 d×d ). Cuturi (2007, Prop.1) also proved that T (r, c ; K) is a positive definite kernel of r and c if both are binary histograms and K is a nonnegative d × d positive definite matrix. Since the computation of T entails in that case the computation of the permanent of a Gram matrix, Cuturi (2007) called this kernel the permanent kernel. The main contribution of our paper is to prove in Theorem 1 that the map (r, 2.3. Relationships with the Optimal Transportation Distance. Given a d× d cost matrix M , one can quantify the cost of mapping r to c using a transportation matrix X as X, M . The minimum of this cost is called the optimal transportation cost, defined as: A classical result of optimization in network flows (Bertsimas and Tsitsiklis, 1997, Theo. 7.5) guarantees the existence of a contingency table . Schematic representation of the set U(r, c) of contingency tables seen as the intersection between the lattice of integral matrices N d×d with the transportation polytope U (r, c). Each red dot stands for an integral plan X ∈ U(r, c). The inner color in each red dot stands for the value of X, M , which can be seen to go gradually from X ⋆ , M to X • , M , that is from the minimum to the maximum of ·, M over U (r, c), or equivalently U(r, c). The generating function V (r, c; M ) of U(r, c) considers the contributions of all contingency tables.
achieves this minimum, as schematically represented in Figure 1. Such an optimal table X ⋆ can be obtained algorithmically in polynomial time (Ahuja et al., 1993, §9). The minimal cost d M (r, c) turns out to be a distance (Villani, 2009, §6.1) whenever the matrix M is itself a metric. This distance is also known as the Wasserstein distance, Monge-Kantorovich's, Mallow's or Earth Mover's (Rubner et al., 1997) in the computer vision literature. The transportation distance is not negative definite in the general case, as shown by counterexamples (Naor and Schechtman, 2007) and embedding distortion results (Andoni et al., 2009). Although some metrics to form an undefinite kernel which can be used to compare histograms in practice. We prove that, although the value exp(− X ⋆ , M ) in itself is not a positive definite kernel, the sum of each term exp(− X, M ) over all possible contingency tables in U(r, c) is positive definite when M has suitable properties. The generating function V rc can be interpreted as the exponential of (minus) the soft-minimum of X, M over all contingency tables, where the soft-minimum of a finite family of scalars (u i ) is This expression relates our results in this work to previous applications of soft minimums to derive positive definite kernels from combinatorial distances for strings (Vert et al., 2004), time series  and trees (Shin et al., 2011). These ideas are summarized in Figure 1.
Note that if ρ and γ have respectively r i and c i elements i among their N coefficients for all 1 ≤ i ≤ d, then χ(ρ ; γ) ∈ U(r, c). One can see above that the corresponding histograms are r = [3, 3, 2] and c = [3, 1, 4] and that both χ(ρ ; γ) and χ(ρ ; γ π ) have row and column sums r and c.

The Weighted Volume as a Positive Definite Kernel
The proof relies on the following observation: Barvinok (2008) showed that the weighted volume of U(r, c) of two integral histograms r and c of total mass N can be formulated as the expectation of the permanent of a random N × N matrix. To do so, Barvinok shows that the weighted volume -a sum indexed over all contigency tables X ∈ U(r, c), can be rewritten as a sum indexed over all permutations π in S N , up to a correcting term known as the Fisher-Yates statistic (Equation (5) in the Appendix). The crux of Barvinok's proof lies in a randomization schemeusing draws from the exponential law -to cancel out the Fisher-Yates statistic. We adopt a similar route to prove the positivity of T , by proving that the inverse of the Fisher-Yates statistic -defined as k 2 below -is itself positive definite to obtain the result.
Proof. Suppose that K ∈ R d×d + is positive definite and consider two integral histograms r, c in Σ N d . We represent r as a N -dimensional vector ρ ∈ {1, · · · , d} N , and consider the analogous representation γ for c. Let k 1 and k 2 be the following kernels on (ρ, γ): The kernel k 2 is the inverse of the Fisher-Yates statistic (Equation (5) in the Appendix) associated to an integral transportation table X and its marginals r and c. k 1 is trivially positive definite. The first group of terms of k 2 is trivially positive definite as a product f (r)f (c) where f (r) = 1 r1!···r d ! . We prove that the other term, the product of factorials of x ij , is positive definite in Lemma 3 using the proof strategy of a related result provided in Lemma 2. Lemma 4 proves that when a kernel κ on two vectors is symmetric (the definition is provided in the lemma), the sum π∈SN κ(ρ, γ π ) is itself positive definite. We use this result on the product κ(ρ, γ) = k 1 (ρ, γ) k 2 (ρ, γ) which is trivially symmetric as the product of two symmetric kernels. We then prove in Lemma 5 that π∈SN κ(ρ, γ π ) = T (r, c ; K).
Since the summation over all permutations in the left hand side is positive definite by Lemma 4, we conclude that T (r, c ; K) is itself a positive definite kernel as the product of two positive definite kernels.

Northwestern Kernel
The weighted volume T (r, c ; K) cannot be computed exactly even for small dimensions d, and approximations (Barvinok, 2008) are currently both too expensive and too loose to be of practical interest in a machine learning context. We adopt in this section an alternative approach, in which we propose to restrict the sum of elementary contributions exp(− X, M ) to a subset of extreme points of U (r, c) and obtain a kernel whose computational complexity grows linearly in both the dimension d and the size of the sample of extreme points. The main tool for this approach is provided by the Northwestern corner rule to generate a vertex of U (r, c), which we recall in Section 4.1. We define the Northwester kernel in Section 4.2 and prove that it is positive definite. For any matrix M ∈ R d×d , we write M σσ ′ for the row and column permuted matrix whose i, j element is m σ(i)σ ′ (j) .

The Northwestern Corner Rule to Generate Vertices of U (r, c). The
Northwestern corner rule is a heuristic that produces a vertex of the polytope U (r, c) in up to 2d operations. The rule starts by giving the highest possible value to x 11 , and at each step when a highest possible value is given to entry x ij it moves on to x ij+1 in case x ij filled column j, or x i+1j in case x ij filled row i. The rule proceeds until x nn has received a value. Here is an example of this sequence assuming r = [2, 5, 3] and c = [5, 1, 4]: We write NW(r, c) for the unique Northwestern corner solution that can be obtained through this heuristic. There is, however, a much larger number of Northwestern corner solutions that can be obtained by permuting arbitrarily the order of r and c separately, computing the corresponding Northwestern corner table, and recovering a table of U(r, c) by inverting again the order of columns and rows. Setting σ = (3, 1, 2), σ ′ = (3, 2, 1) we have that r σ = [3, 2, 5], c σ ′ = [4, 1, 5] and σ −1 = (2, 3, 1), σ ′ = (3, 2, 1). Observe that: Let N (r, c) be the set of all Northwestern corner solutions that can be produced this way: Note that all Northwestern corner solutions only have by construction up to 2d − 1 nonzero elements. The Northwestern corner rule produces a table which is by construction unique for r and c, but there is an exponential number of pairs or row/column permutations (σ, σ ′ ) that may share the same table (Stougie, 2002, p.2). N (r, c) is a subset of the set of extreme points of U (r, c) (Brualdi, 2006, Corollary 8.1.4). NW(r, c) is an optimal transportation between r and c if the cost matrix M is a Monge matrix (Hoffman, 1961), that is a matrix M that satisfies the inequalities ∀1 ≤ i, j, k, l ≤ d, m ij + m kl ≤ m il + m kj .
Note however that a distance matrix cannot be a Monge matrix since the inequality above applied to k = j and l = i would imply that 0 < 2m ij ≤ m ii + m jj = 0.

4.2.
Random Sampling of Northwestern Corner Solutions. We propose in this section a kernel which uses arbitrary row/column permutations of r and c to recover extreme points of U(r, c) and sum their individual contribution: Theorem 2. Let R be an arbitrary subset of permutations in S d . The Northwestern kernel sampled on R and parameterized by a matrix M , defined as is a positive definite kernel if K, the element-wise exponential of −M , is positive definite.
Proof. As in the proof of Theorem 1, consider the representation of an integral histogram r ∈ Σ N d as a N dimensional vector ρ that replicates r i times the index i for all i from 1 to d. We also define, for any permutation σ of S d , the vector ρ σ as ρ σ for σ ∈ S d should not be confused with ρ π for π ∈ S N ( §2.4): for any permutation σ ∈ S d there exists at least one permutation π ∈ S N such that ρ σ = ρ π but the converse is not usually true. We show in Lemma 1 that for σ, σ ′ ∈ S d , NW σ −1 σ ′−1 (r σ , c σ ′ ) = χ(ρ σ , γ σ ′ ), and thus, where k 1 is defined in Theorem 1. N (r, c ; K, R) is positive definite as a convolution kernel.
Lemma 1. Let σ and σ ′ be two permutations of S d . Then Proof. We write E ij for the d × d matrix of zeros except for the (i, j) element set to 1. We prove the result by induction on the total mass N . For N = 1 the result is trivial since the only transportation matrix in U (r, c) in that case is E σ(i1)σ(i2) , where i 1 and i 2 are such that r i1 = c i2 = 1. Suppose now that the result is true for all histograms of mass N and consider the case where r T 1 d = c T 1 d = N + 1. Let i 1 and i 2 be the smallest indices such that r σ(i) > 0 and c σ ′ (i) > 0 respectively. As a consequence, the first elements of ρ σ and γ σ ′ are σ(i 1 ) and σ(i 2 ) respectively. Consider the two vectors ρ * and γ * of length N equal to ρ σ and γ σ ′ without these two first elements. Settingr andc to r and c except for the fact thatr σ(i1) = r σ(i1) − 1 andc σ(i2) = r σ(i2) − 1, we have by induction that NW σ −1 σ ′−1 (r σ ,c σ ′ ) = χ(ρ * , γ * ), since the two histograms have total mass N and their representations are respectively ρ * and γ * . By definition of the Northwestern corner rule, adding a unit of mass to the i 1 's and i 2 's components ofr σ andc σ ′ only changes the very first iteration of the rule, since all coordinates ofr σ andc σ ′ up to but not including i 1 and i 2 respectively are null by construction. Applying the rule yields a transportation table with an added unit in location (i 1 , i 2 ), providing thus the identity NW(r σ , c σ ′ ) = NW(r σ ,c σ ′ ) + E i1i2 , which implies that By definition of χ we have that we get by combining Equations (4) and (3) above with the induction hypothesis that NW σ −1 σ ′−1 (r σ , c σ ′ ) = χ(ρ σ , γ σ ′ ).
Remark 1. The evaluation of N (r, c ; K, R) requires O(d|R| 2 ) steps since computing each of the |R| 2 contributions exp(− M, NW σ −1 σ ′−1 (r σ , c σ ′ ) ) for a couple σ, σ ′ requires up to 2d products. The size of R ⊂ S d can be controlled from a few permutations to an exhaustive enumeration, which would entail an overall complexity of the order of O(dd! 2 ).

Conclusion and Future Work
We have proved in this paper that the fundamental ingredient of transportation distances, the polytope of contingency tables, can be used to define a positive definite kernel between two histograms. While the cost matrix of a transportation problem between two histograms r and c needs to be a distance matrix for the optimum to be itself a distance of r and c, we have proved that the generating function of the same polytope is positive definite whenever the cost matrix is itself positive definite. This quantity is computationally intractable, and we have resorted to a summation that only considers a subset of extreme points of the polytope to define the north-western kernel. Future research includes the proposal of suitable subsets R of permutations of S d tuned with data, as well as other approximation schemes.
Appendix: Intermediate Results for the Proof of Theorem 1 Lemma 2. Let a, b ∈ {0, 1} N be two binary vectors. The kernel (a, b) → a, b ! is positive definite.
Proof. For N = 1 the kernel is always equal to 1 and is thus trivially positive definite. For N > 1, the recursion a, b ! = a N −1 which shows that a, b ! is the product of N − 1 positive definite kernels on different features of a and b.
Remark 2. Rather than the lemma itself, we will use the identity above in the proof of Lemma 3. We conjecture that this result can be extended to integral vectors. Numerical counterexamples show that this result cannot be generalized to vectors of R N through Euler's or Hadamard's Γ function.
Proof. An integral vector ρ ∈ {1, · · · , d} N with N components can be represented as a family of d binary row vectors ρ 1 , · · · , ρ d of length N where for n ≤ N , These d binary vector representations can be used to obtain the matrix χ(ρ ; γ). Indeed, it is easy to check that if X = χ(ρ , γ) then x ij = ρ i , γ j . As a consequence, we have that for all indices i, j the coefficient x ij ! = ρ i , γ j !. We obtain that the product of factorials is thus a product of kernels evaluated on all possible pairs among the d × d representations for ρ and γ. Although one might be tempted to interpret this product as a convolution kernel (Haussler, 1999) or a mapping kernel (Shin and Kuboyama, 2008), one should recall that such results only apply to sums of local kernels and not to products. Such products of kernels on parts are not, as simple counterexamples can show, positive definite in the general case. Using the decomposition which was used in the proof of Lemma 2, we have however that: where we have used in the last operation the fact that only one of all d 2 products (ρ i t+1 γ j t+1 ) ij is nonzero, since ρ i t+1 γ j t+1 = 1, if ρ t+1 = i and γ t+1 = j, 0, else.
which proves the result.
Lemma 5. π∈SN κ(ρ, γ π ) = r 1 ! · · · r d ! · c 1 ! · · · c d ! T (r, c ; K) Proof. For any couple of vectors ρ, γ we have that both k 1 and k 2 only depend on X = χ(ρ ; γ). This is implicitly the case in the definition of k 2 and one can check that With every permutation π of we associate a transportation table χ(ρ ; γ π ) which we call the pattern of π. Following (Barvinok, 2008, §2,p.7), we know that the number of permutations π that share the same pattern X for X ∈ U(r, c) only depends on X, r and c through a formula known as the Fisher-Yates statistic n(X) of X, n(X) def = card{π ∈ S N | χ(ρ ; γ π ) = X} = r 1 ! · · · r d ! · c 1 ! · · · c d ! ij x ij ! .
Graduate School of Informatics, Kyoto University E-mail address: mcuturi@i.kyoto-u.ac.jp