{'fraction_non_alphanumeric': 0.0471682913075002, 'fraction_numerical': 0.022556996697011198, 'mean_word_length': 4.209190096516996, 'pattern_counts': {'":': 0, '<': 2, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
On the Needs for Rotations in Hypercubic Quantization Hashing

The aim of this paper is to endow the well-known family of hypercubic quantization hashing methods with theoretical guarantees. In hypercubic quantization, applying a suitable (random or learned) rotation after dimensionality reduction has been experimentally shown to improve the results accuracy in the nearest neighbors search problem. We prove in this paper that the use of these rotations is optimal under some mild assumptions: getting optimal binary sketches is equivalent to applying a rotation uniformizing the diagonal of the covariance matrix between data points. Moreover, for two closed points, the probability to have dissimilar binary sketches is upper bounded by a factor of the initial distance between the data points. Relaxing these assumptions, we obtain a general concentration result for random matrices. We also provide some experiments illustrating these theoretical points and compare a set of algorithms in both the batch and online settings.


Introduction
Nearest neighbors (NN) search is a key task involved in many machine learning applications such as classification or clustering. For large-scale datasets e.g. in computer vision or metagenomics, indexing efficiently high-dimensional data becomes necessary for reducing space needs and speed up similarity search. This can be classically achieved by hashing techniques which map data onto lower-dimensional representations. Two hashing paradigms exist: data-independent and data-dependent hashing methods. On the one hand, Locality-Sensitive Hashing (LSH) (Andoni and Indyk [2008]) and its variants (Terasawa and Tanaka [2007], Andoni et al. [2015], Yu et al. [2014]) belong to the data-independent paradigm. They rely on some random projection onto a c-lower dimensional space followed by a scalar quantization returning the nearest vertex from the set {−1, 1} c for getting the binary codes (e.g. the sign function is applied point-wise). On the other hand, data-dependent methods (Wang et al. [2018]) learn this projection from data instead and have been found to be more accurate for computing similarity-preserving binary codes. Among them, the unsupervised data-dependent hypercubic hashing methods, embodied by ITerative Quantization (ITQ) (Gong et al. [2013]), use Principal Component Analysis (PCA) to reduce data dimensionality to c: the data is projected onto the first c principal components chosen as the ones with highest explained variance as they carry more information on variability. If we then directly mapped each resulting direction to one bit, each of them would get represented by the same volume of binary code (1 bit), although the c th direction should carry less information than the first one. Thus, one can intuitively understand why PCA projection application solely leads to poor performance of obtained binary codes in the NN search task. This is why data get often mixed though an isometry after PCA-projection so as to balance variance over the kept directions. Works from Jégou et al. [2010] and Chen et al. [2017] use a random rotation while the rotation can also be learned (Gong et al. [2013], Kong and Li [2012]) to that purpose. This led to the development of variant online techniques such as Online Sketching Hashing (OSH) (Leng et al. [2015b]), FasteR Online Hashing (FROSH) (Chen et al. [2017]), UnifDiag (Morvan et al. [2018]) which are deployable in the streaming setting when large high-dimensional data should be processed with limited memory. These are currently the state-of-the-art of online unsupervised hashing methods for learning on the fly similarity-preserving binary embeddings. Nevertheless, even if one can now use these unsupervised online methods for processing high-dimensional streams of data, there is still no theoretical justification that equalizing the variance or in other words choosing directions with isotropic variance leads to optimal results.
Contributions: The main contribution of this paper is to bring theoretical guarantees to several state of the art quantization-based hashing techniques, by formally proving the need for rotation when the methods rely on PCA-like preprocessing. We also introduce experiments accompanying the theoretical results and extend ones comparing existing online unsupervised quantization-based hashing methods.

Related work
Two paradigms stand for building hash functions: data-independent (Andoni and Indyk [2008], Raginsky and Lazebnik [2009], Grauman and Kulis [2011]) and data-dependent methods (Wang et al. [2018]). For the latter category, the binary embeddings are learned from the training set and are known to work better. Among this branch of methods, unsupervised methods (Weiss et al. [2008], Liu et al. [2011], Gong et al. [2013], Kong and Li [2012], Lee [2012], Liu et al. [2014], Yu et al. [2014], Raziperchikolaei and Carreira-Perpiñán [2016]) design hash codes preserving distances in the original space while (semi-)supervised ones attempt to keep label similarity , Liu et al. [2012]). Work from (Wang et al. [2018]) proposes an extensive survey of these methods and makes further distinctions to finally show that quantization-based techniques are superior in terms of search accuracy. We can cite: ITerative Quantization (ITQ) (Gong et al. [2013]), Isotropic Hashing (IsoHash) (Kong and Li [2012]), Cartesian K-means (Norouzi and Fleet [2013]), deep-learning-based methods (Lai et al. [2015], Liong et al. [2015], Do et al. [2016]). Specifically, when the dataset is too large to fit into memory, distributed hashing can be used (Leng et al. [2015a]) or online hashing techniques (Huang et al. [2013], Leng et al. [2015b], Cakir and Sclaroff [2015], Cakir et al. [2017], Morvan et al. [2018]) can process the data in only one pass, as a continuous stream, and compute binary hash codes as new data is seen. This latter area has attracted lots of interest in the past few years. Online Hashing (OKH) (Huang et al. [2013]) learns the hash functions from a stream of similarity-labeled pair of data with a "Passive-Aggressive" method. Supervised MIHash algorithm (Cakir et al. [2017]) also uses similarity labels between pairs of data and consider Mutual Information for computing the binary embeddings. On the unsupervised side, in Online Sketching Hashing (OSH) (Leng et al. [2015b]), the binary embeddings are learned from a maintained sketch of the dataset with a smaller size which preserves the property of interest. UnifDiag, the recent approach from Morvan et al. [2018], learns the hash codes from an online estimated principal space and the balancing rotation as a sequence of Givens rotation whose coefficients are computed so as to equalize diagonal coefficients of the PCA-projected data covariance. In the same work, it has also been shown how to adapt IsoHash (Kong and Li [2012]), which is not originally an online technique, to the streaming setting.

Notations and problem statement
In the sequel, for a given integer a, [a] = {1, . . . , a}. Let us define the sign function s.t. for any real x, sign(x) = 1 if x ≥ 0 and −1 otherwise. We also use this notation for the same function applied componentwise on coefficients of vectors. ||.|| F denotes the Froebenius norm. Tr(.) stands for the Trace application. Let be a stream of n zero-centered data points {x t ∈ R d } 1≤t≤n . The considered hashing methods aim at obtaining binary codes b t = sign(W x t ) ∈ {−1, 1} c for t ∈ [n], where: c denotes the code length, c d, andW ∈ R c×d is the dimensionality reduction operator. In other words, for each bit k ∈ [c], the hashing function is defined as h k (x t ) = sign(w T k x t ) wherew k are column vectors of hyperplane coefficients. Sõ w T k is a row ofW ∈ R c×d for each k. In the framework of hypercubic quantization hashing functions, W = RW where W is the linear dimension reduction embedding applied to data and R is a suitable c × c orthogonal matrix. Typically, one can take W as the matrix whose row vectors w T k are the c first principal components of the covariance matrix Σ X where X = [x 1 , . . . , x n ] ∈ R d×n . Please note that this problem statement includes offline and online methods: W can be either the PCA or a tracked principal subspace as new data is seen. What is more specific to the methods is the way of learning the appropriate orthogonal matrix 1 for rotating the data previously projected onto this principal subspace. After application of the (possibly online estimated) PCA algorithm, the stream becomes {v t ∈ R c } 1≤t≤n s.t. v t = W x t . Then, for all t ∈ [n], y t = Rv t and b t = sign(y t ). In the sequel, depending on the context, we will be considering either one data point x t , its initial projection v t = W x t , its rotated projection y t and binary sketch b t , or the whole associated sets X,

ITerative Quantization (ITQ) (Gong et al. [2013])
For ITQ, R is the solution of an orthogonal Procustes problem which consists in minimizing quantization error Q(B, R) of mapping resulting data to the vertices of the 2 c hypercube: R is initially some random orthogonal matrix. Then, iteratively, ITQ alternatively computes B = sign(RW X) after freezing R, and optimizes R according to B. In the latter step, R =SS T by defining S, Ω,S T = SVD(B T V ) the Singular Values Decomposition (SVD) of B T V . Hence, ITQ's goal is to map the values of projected data to their component-wise sign.

Methods based on uniformizing diagonal coefficients of covariance matrix
Let σ 2 1 , ..., σ 2 c be the diagonal coefficients of Σ V , hence σ 2 1 ≥ ... ≥ σ 2 c . The methods described thereafter look for a matrix R balancing variance over the c directions, i.e. equalizing the diagonal coefficients of Σ Y to the same value τ = Tr(Σ V )/c.

Isotropic Hashing (IsoHash) (Kong and Li [2012])
Let us define, for any real a, T (a), the set of all c × c matrices with diagonal coefficients equal to a: Then, in IsoHash, the chosen way for determining R is to solve the following optimization problem: In the sequel, the terms orthogonal matrix or rotation are used equivalently.
One of the proposed methods by IsoHash to solve this problem (Gradient Flow ) is to reformulate it as the following: Then, the rotation results from a gradient descent converging to the intersection between the set of orthogonal matrices and the set of transfer matrices making Σ Y diagonal.
Definition 3.1. A Givens rotation G(i, j, θ) is a matrix of the form: where i > j, c = cos(θ) and s = sin(θ); ∀k = i, j, g k,k = 1; g i,i = g j,j = c, g j,i = −s and g i,j = s. All remaining coefficients are set to 0.
Some Givens rotations are iteratively applied left and right to Σ V during the iterative Jacobi eigenvalue algorithm for matrix diagonalization (Golub and van der Vorst [2000]). For r ∈ [c − 1], given i r , j r , θ r , where (Σ Y ) 0 = Σ V , R 0 = I c . At each step r, i r and j r are chosen to be the indices of the current smallest and largest diagonal coefficients of (Σ Y ) r−1 .θ r is computed accordingly so that at the end of step r, r diagonal coefficients of (Σ Y ) r are equal to τ .

Theoretical justification of optimality of a rotation R for hypercubic quantization hashing
We deliver in this Section three results on the theoretical justification of applying R after PCA projection in terms of efficiency of the binary sketches. We prove in Section 4.1, assuming some distribution on data, 1) the optimality of choosing R as a rotation uniformizing the diagonal of the covariance matrix and 2) we provide some lower bound on the probability of getting different binary sketches for two data points initially close to each other. 3) Then we propose an extension to the case with no assumption on data distribution but some on matrix R in Section 4.2. Given an upper bound on the distance between two data points in the initial space, we give a lower bound on the number of bits in common in their binary sketches.

When rotation R uniformizes the diagonal of the covariance matrix
In this section, we assume R ∈ R c×c is a rotation matrix (RR T = R T R = I c ).
Hypothesis 4.1 (H1). We assume: Before introducing Th. 1, please note that two neighboring data points can have very dissimilar binary codes if their projections on PCA have many coefficients near zero, not on the same side of the hyperplanes delimiting the orthants. Indeed, in this case, the sign function will attribute opposite bits. Therefore, after dimensionality reduction of the data points in the original space, a good hashing method tends to keep the coefficients of the projected data away from zero, i.e. away from the orthant. The challenge is then to determine how to move these data points away from the orthants.
is a stream of n zero-centered data points following Hypothesis 4.1. Then, choosing R so that it uniformizes the diagonal of the covariance matrix Σ th Y is equivalent to minimizing some upper bound on the probability that data points are closed to an hyperplane delimiting an orthant.
Proof. Let > 0. For i ∈ [c], t ∈ [n], let p i be the probability (independent of t) that y (i) t = (Rv t ) (i) is closer than from the orthant: Then, Eq. 5 and 6 give: Minimal value of If moreover Σ th V is diagonal, inequality 4 becomes an equality. Thus, choosing R so that it uniformizes the diagonal of the covariance matrix Σ th Y is exactly equivalent to minimizing the probability that data points are closed to an hyperplane delimiting an orthant plus o( 2 ), where is the distance to the orthant.
Please note that in practice the algorithm uniformizes the diagonal coefficients of the empirical covariance matrix Σ V . This still makes sense because 1 n Σ V is a consistent estimator of the theoretical covariance matrix Σ th V . Now we can bound the probability of getting dissimilar sketches for data points close to each other, as stated in Th. 2 below: Theorem 2. Let x t1 ∈ R d and x t2 ∈ R d be two data points following Hypothesis 4.1, > 0 so that Then, the probability of getting dissimilar binary sketches is upper bounded as follows: Proof. As PCA performs a projection, one has: ||v t1 − v t2 || 2 ≤ ||x t1 − x t2 || 2 ≤ . Then, ||y t1 − y t2 || 2 ≤ since R preserves the norm as a rotation. Thus, in particular, for all i ∈ [c], |y because |y Since y t1 and y t2 have same distribution and using Th. 1, The result follows.

When matrix R is random
We now show that if we assume R is a random matrix that resembles a random rotation (i.e. we do not optimize R and furthermore R is not a valid rotation matrix) we can still get strong guarantees regarding the quality of the hashing mechanism (even though not as strong as in the case when R is optimized). We will assume that R is a Gaussian matrix with entries taken independently at random from N (0, 1). We further make some assumptions regarding the input data and the quality of the PCA projection mechanism.
Hypothesis 4.2 (H2). We assume that the variance of the norm of vectors x t is upper-bounded, namely we assume that l(1−δ) ≤ x t 2 ≤ l(1+δ) for some fixed l, δ > 0. We also assume that the PCA projection encoded by matrix W satisfies for every t: W x t − x t 2 ≤ x t 2 for some > 0. The latter condition means that the fraction of the L 2 -norm of the vector lost by performing a PCA projection is upper-bounded (better quality PCA projections are characterized by smaller values of ).
We now state the main theoretical result of this section: Theorem 3. Let x t1 , x t2 ∈ R d be two data points following Hypothesis 4.2 for some constants l, δ, > 0. Then for every ρ > 0 the following holds: if x t1 − x t2 2 ≤ ρ and b t1 ∈ {−1, 1} c and b t2 ∈ {−1, 1} c with b t1 = sign(RW x t1 ) and b t2 = sign(RW x t2 ) then for any η > 0 with probability at least 1 − e − η 2 c 2 the number of bits in common between b t1 and b t2 is lower bounded by q satisfying Proof. Note that by Hypothesis 4.2 and triangle inequality, we know that Now consider a particular entry j ∈ {1, . . . , c} of two binary codes: b t1 and b t2 . Note that b where r i stands for the transpose of the i th row of R. We have: where r i proj stands for the orthogonal projection of the vector r i into a 2-dimensional linear space spanned by {v t1 , v t2 } and r i ort denoted the part of the vector r i that is orthogonal to that subspace. Similarly, we obtain: Therefore we have: b . Denote by L the subset of the two-dimensional subspace spanned by {v t1 , v t2 } that consists of these vectors v ∈ R c that satisfy: Now note that the projection r i proj of the Gaussian vector r i into two-dimensional deterministic linear subspace spanned by {v t1 , v t2 } is still Gaussian. Furthermore, Gaussian vectors satisfy the isotropic property. The probability that b (i) t1 and b (i) t2 are the same is exactly the probability that r i proj ∈ L. From the fact that r i proj is Gaussian and the isotropic property of Gaussian vectors (Charikar [2002]) we conclude that: where θ vt 1 ,vt 2 stands for an angle between v t1 and v t2 . Besides, we have: Note that by property of the PCA, one has: ||v t1 || 2 ≤ ||x t1 || 2 and ||v t2 || 2 ≤ ||x t2 || 2 . Moreover, triangle inequality gives: From the above and by using Eq. 12 we get: Hence, t2 are the same and is 0 otherwise. Note that the probability that X i is nonzero is exactly Note also that different X i are independent since different rows r i of the matrix R are independent. If we denote by X a random variable defined as: then note that E[X] = pc. This random variable X counts the number of entries of b t1 and b t2 that are the same. Now, using standard concentration results such as Azuma's inequality, we can conclude that for all a > 0 : In particular, for a = ηc, Then with probability at least 1 − e − η 2 c 2 , X ≥ c(p − η). Putting the formula on p from Eq. 19 and the obtained upper bound on θ vt 1 ,vt 2 from Eq. 18, we complete the proof.

Experiments
Experiments have been carried out on a single processor machine (Intel Core i7-5600U CPU @ 2.60GHz, 4 hyper-threads) with 16GB RAM and implemented in Python (code will be available after publication).

Comparison of Hypercubic Quantization Hashing methods for the Nearest Neighbors search task
We propose first further experiments in comparison with the recent approach from Morvan et al. [2018] for more code lengths in batch and online setting. Quality of hashing is assessed here on the Nearest Neighbors (NN) search task: retrieved results of the NN search task performed on the c-bits codes of hashed data points are compared with the true nearest neighbors induced by the Euclidean distance applied on the initial d-dimensional real-valued descriptors. Mean Average Precision (MAP), commonly used in Information Retrieval tasks, measures then the accuracy of the result by taking into account the number of well-retrieved nearest neighbors and their rank. Based on the MAP criteria, two types of experiments are presented: 1) UnifDiag algorithm is compared with batch-based methods to show that the streaming constraint does not make loose too much accuracy in NN search results. 2) In the online context, the algorithm is set against to existing online methods in order to exhibit its efficiency. In both cases, tests were conducted on two datasets: CIFAR-10 (http://www.cs.toronto.edu/~kriz/cifar.html) and GIST1M (http://corpus-texmex.irisa.fr/). CIFAR-10 (CIFAR) contains 60000 32 × 32 color images equally divided into 10 classes. 960-D GIST descriptors were extracted from those data. GIST1M (GIST) contains 1 million 960-D GIST descriptors, from which 60000 instances were randomly chosen from the first half of the learning set. To perform the NN search task, 1000 queries are randomly sampled and the 59000 remaining data points are used as training set. Then, the sets of neighbors and non-neighbors of the queries are determined by a nominal threshold which is arbitrarily chosen to be the average distance to the 600 th nearest neighbor in the training set (1% of each dataset). After binary hashing of the query and training sets, MAP at 2000 is computed over the first 2000 retrieved nearest neighbors from the training set according to sorted values of Hamming distance between the binary codes. Indeed, we are obviously interested in nearest neighbors returned first, so M AP @2000 is enough. Results are averaged over 5 random training/test partitions.

Comparison with batch-based methods
In the offline setting, the hashing function is learned over the whole training set and the final MAP is printed for different c value. Fig. 1 shows MAP results for UnifDiag against unsupervised batchbased methods: ITQ (K = 50) and IsoHash (original version preceded by a PCA projection), for an evaluation after having seen the whole training set. The online estimation of the principal subspace via OPAST instead of the classical PCA does not lead to a loss of accuracy, since UnifDiag reaches similar performances to batch-based methods for every code lengths.

Comparison with online methods
In the online setting, we print the MAP after every 5 data points until the 3000 because a plateau is then reached (but the NN are still computed over the whole training set). We compared here four unsupervised online baseline methods that follow the basic hashing scheme Φ(x t ) = sgn(W t x t ), where the projection matrixW t ∈ R c×d is determined according to the chosen method: 1) OSH (Leng et al. [2015b]): the number of chunks/rounds is set to 100 and l = 200. 2) RandRotOPAST: W t is the PCA matrix obtained with OPAST and R t a constant random rotation. 3) IsoHashOPAST: R t is obtained with IsoHash. 4) UnifDiagOPAST (Morvan et al. [2018]). Fig. 2

Effect of rotation on binary sketches
In this Section, in the offline context, the experiments shed light on the theory above by showing why a rotation gives better binary sketches than simply PCA projection. Rotations considered are random or learned from ITQ, IsoHash and UnifDiag. First, for CIFAR and GIST datasets, we compute the cumulative distribution function of P[|y (i) t | < ], i.e. the probability for all t ∈ [n] of y t ∈ R c to have entries near zero before and after the rotation application. Fig. 4 plots P[|y (i) t | < ] for c = 32 (averaged on 5 runs). Similar results are obtained for other code lengths. For all rotation-based methods, this probability is always lower similarly than the one associated to only PCA projection.
Secondly, we provide a visualization of the rotation efficiency in the clustering task. This experiment is made on simulated data since a ground truth partition is required. We consider C equally distributed clusters of n data points such that nearest neighbors of a data point are points from the same cluster. We choose the centroids from these clusters randomly. The expected result is a small variance of the binary codes within the same cluster. Fig. 5 displays the binary sketches obtained with and without rotation for C = 6, n = 6000 points with d = 960 and c = 32. Each column is a binary sketch: a yellow case represents a bit equal to 1 and a red pixel stands for −1. Each cluster, delimited by a blue vertical line, contains  PCA 7.1 × 10 −2 6.5 × 10 −2 4.0 × 10 −2 2.2 × 10 −2 randRot 3.9 × 10 −4 2.6 × 10 −4 1.9 × 10 −4 7.4 × 10 −5 ITQ 0.0 2.0 × 10 −4 1.1 × 10 −4 1.3 × 10 −4 UnifDiag 4.1 × 10 −4 2.2 × 10 −4 2.5 × 10 −4 1.1 × 10 −4 IsoHash 1.4 × 10 −4 3.3 × 10 −4 2.1 × 10 −4 1.3 × 10 −4 1000 points plotted in order. An interpretation of the results is that the rotation tends to move data away from the orthant since more binary sketches after application of the rotation have bits in common. This is illustrated by the obtained blocks of the same color, as opposed to the "blurry" visualization implied by the PCA alone. More quantitatively, Table 1 compiles the variance of the binary sketches averaged on the 6 clusters for 10 partitions. Not surprisingly, PCA gives the worst results: the high variance in the binary sketches explains the "blurry" previous visualization. Conversely, all rotation-based methods tend to reduce the variance in the binary sketches.

Conclusion
State-of-the-art unsupervised hypercubic quantization hashing methods preprocess data with Principal Component Analysis and then rotate them data to balance variance over the different directions. It has been shown to give better sketches accuracy in the nearest neighbors search task but to the best of our knowledge, this is the first time that theoretical guarantees are provided. In particular, rotations uniformizing the diagonal of the data covariance matrix are interesting since they enable to deploy the sketching algorithm in the streaming setting. As there exists possibly an infinity of rotations uniformizing the covariance matrix diagonal, further investigation would be to evaluate among them which ones perform better.