{'fraction_non_alphanumeric': 0.04010840108401084, 'fraction_numerical': 0.010677506775067751, 'mean_word_length': 4.0997788833609725, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 1, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Similarity Between Points in Metric Measure Spaces

This paper is about similarity between objects that can be represented as points in metric measure spaces. A metric measure space is a metric space that is also equipped with a measure. For example, a network with distances between its nodes and weights assigned to its nodes is a metric measure space. Given points x and y in different metric measure spaces or in the same space, how similar are they? A well known approach is to consider x and y similar if their neighborhoods are similar. For metric measure spaces, similarity between neighborhoods is well captured by the Gromov-Hausdorff-Prokhorov distance, but it is NP-hard to compute this distance even in quite simple cases. We propose a tractable alternative: the radial distribution distance between the neighborhoods of x and y. The similarity measure based on the radial distribution distance is coarser than the similarity based on the Gromov-Hausdorff-Prokhorov distance but much easier to compute.


Introduction
A metric measure space is a metric space that is also equipped with a measure. Such spaces play an important role in geometry, especially after Gromov's works [8], and they have proven to be useful in other areas of mathematics, for example, in optimization theory [2] and in probability theory [4]. Metric measure spaces are also used to model real-world systems and processes, for example, in image recognition [11], in genetics [15], in machine learning [3], etc.
A natural example of a metric measure space is given by a connected graph G in which all vertices and edges are labeled with numbers: the number assigned to a vertex is its "weight" and the number assigned to an edge is its "length". The corresponding metric space is formed by the set of all vertices with the shortest path metric in G: the distance between two vertices is the length of a shortest path between them. A measure on this space is defined on all subsets of the vertices: the measure of a subset A is the total weight of all vertices of A. The weights and lengths can be interpreted in various ways. For example, if G is a communication network, then the weight of a vertex can describe the traffic at this vertex. Another example: if G is a propagation network in epidemic models, then the weight can be the number of infected individuals.
Consider objects that can be modeled by points in metric measure spaces: suppose one object is represented by a point x in a space X and another object is represented by a point y in a space Y. How similar are these objects? How can we measure similarity between them if the only information we have is the pairs (X , x) and (Y, y)? Such pairs are called rooted metric measure spaces or rooted mm spaces for short, see Section 2 for precise definitions. In this paper we address the question of similarity between objects modeled by rooted mm spaces.
The most obvious type of similarity between (X , x) and (Y, y) is an isomorphism between them, which means that there is a bijection from X to Y that maps x to y and preserves the metric and measure. This is an "all or nothing" measure of similarity: any two rooted mm spaces are either similar or not. Clearly, this measure is not a good solution for applications because real-world objects, like social, biological, or technological networks, are very rarely, if ever, isomorphic to one another.
Can we improve the isomorphism-based approach to make it more flexible? How could we measure to what extent (X , x) and (Y, y) look isomorphic? The concept of "approximate isomorphism" between rooted mm spaces can be implemented using the idea proposed by Edwards [6] and Gromov [7]. To compare (X , x) and (Y, y), we embed X and Y into another metric measure space Z and compare their images in Z. More exactly, we take embeddings f and g that preserve the metric and measure and compare the images f (X ) and g(Y) in Z. We consider (X , x) and (Y, y) similar if their images are close to each other in the following sense: the point f (x) is close to the point g(y) in the space Z; -the set of points of f (X ) is close to the set of points of g(Y) in the space Z; -the measures induced by f and g in Z are close to one another.
The second condition is formalized using the Hausdorff distance and the third condition is formalized using the Lévy-Prokhorov distance, see Section 2. Taking the infimum over all possible spaces Z and embeddings f and g, we obtain a distance function on rooted mm spaces called the Gromov-Hausdorff-Prokhorov distance (the GHP distance for short).
Both the isomorphism-based similarity measure and the GHP-based similarity measure have the following disadvantage for applications. Most real-world systems have the distance decay effect, also called the gravity model, which is often expressed as "all things are related, but near things are more related than far things". For example, when comparing points x and y in metric spaces, the role of their local neighborhoods is more important than the role of points that are far away from x and y. However, neither the isomorphism approach nor the GHP distance capture this effect: all points are considered equally important, independently of their distance from x and y.
This disadvantage is eliminated using the distance defined in [1]. Loosely speaking, this distance between two rooted mm spaces combines the GHP dis-tance with an exponential decay: a point is taken into account with a weight that exponentially decreases with increasing its distance from the root. We call it the neighborhood-based distance and describe it in Section 2.
Intuitively, the neighborhood-based distance is the best approach to capture similarity between points in metric measure spaces. To put this distance to work in practical applications, we need to compute it efficiently. However, it is NP-hard to compute the neighborhood-based distance, which follows from [12]. Moreover, under standard complexity-theoretic assumptions, it is not possible to approximate it with a reasonable factor in polynomial time [16].
In Section 3, we propose a tractable alternative to the neighborhood-based distance: namely, we define the radial distribution distance between rooted mm spaces. This distance can be viewed as a coarser variant of the neighborhoodbased distance or, more exactly, as a lower bound on the neighborhood-based distance. The advantage of the radial distribution distance is that it can be computed efficiently: a straightforward algorithm that computes this distance between finite rooted mm spaces takes time quasilinear in the total number of points.
What is the idea of radial distribution distance? First, we view a point x in a metric measure space X as the center of a ball of radius r around x. This ball has its own measure (its "mass") and we consider how such masses change with increasing r. Second, we consider this change of masses with an exponential distance decay, which means that the "contribution" of points exponentially decreases with increasing their distance from x. The radial distribution distance between (X , x) and (Y, y) is basically the distance between two functions that describe the change of masses around x in X and around y in Y.

Neighborhood-Based Distance
A metric measure space is usually defined as a complete separable metric space with a Borel measure on this metric space. However, in this paper, we deal with only compact metric spaces and finite measures. Therefore, to simplify terminology, we use the term "metric measure space" to refer to this restricted case.
Definition 1 (mm space). Let X be a set and d be a metric on X such that (X, d) is a compact metric space. Let µ be a Borel measure on this metric space. The triplet (X, d, µ) is called a metric measure space (an mm space for short). We use the following notation for balls in metric spaces: for every number r ∈ [0, ∞) and every point x ∈ X, For every number r > 0 and every nonempty subset S ⊆ X, the r-neighborhood of S, denoted by N r (S), is the union of open balls of radius r around the points of S. Let S 1 and S 2 be nonempty subsets of X. The Hausdorff distance between them is defined by Given two subsets of points in a metric space, the Hausdorff distance shows how close they are. Given two measures on a metric space, how close are they? This question is answered by the Lévy-Prokhorov distance, a measure-theoretic analogue of the Hausdorff distance, defined as follows. Let µ 1 and µ 2 be finite Borel measures on a metric space (X, d). Let B be the Borel σ-algebra on (X, d).
The Lévy-Prokhorov distance (sometimes called the Prokhorov distance) between these measures, denoted by π, is given by Measuring similarity between points in different mm spaces or in the same space, it is convenient to deal with rooted mm spaces (sometimes called pointed mm spaces).
A general approach to comparing rooted mm spaces was outlined in Section 1. This approach combines the idea of Gromov-Hausdorff distance with the idea of Lévy-Prokhorov distance. The combination was introduced in [13] and has slight variations. The following definition is the version from [9].
Definition 3 (GHP distance). Let (X 1 , o 1 ) and (X 2 , o 2 ) be rooted mm spaces with X 1 = (X 1 , d 1 , µ 1 ) and X 2 = (X 2 , d 2 , µ 2 ). The Gromov-Hausdorff-Prokhorov distance (the GHP distance for short), denoted d GHP , is defined by where the infimum is taken over all mm spaces Y and all measurable isometries f 1 : X 1 → Y and f 2 : X 2 → Y. The distances d, d H , and π denote respectively the distance, the Hausdorff distance, and the Lévy-Prokhorov distance in Y. The measures are the push-forward measures.
As noted in Section 1, the GHP distance has the disadvantage that d GHP does not capture the distance decay effect occurring in most real-world systems. This disadvantage is eliminated in the distance defined in [1]. We define a simplified version of this distance below and call it neighborhood-based distance. Its idea can be informally described as follows. When comparing rooted mm spaces (X 1 , o 1 ) and (X 2 , o 2 ), we consider the restrictions of X 1 and X 2 to closed balls of radius r around o 1 and o 2 . For every radius r, we consider the GHP distance between the corresponding restrictions and sum up these distances over all values of r with an exponential decrease when r increases.
Let B be a closed ball in an mm space X = (X, d, µ). This ball, along with the metric and measure obtained by restricting d and µ to B, form the mm space called the restriction of X to B.
Definition 4 (neighborhood-based distance). Let (X 1 , o 1 ) and (X 2 , o 2 ) be rooted mm spaces. For every number r ∈ [0, ∞), let δ r denote the GHP distance between the restriction of X 1 to B r (o 1 ) and the restriction of X 2 to B r (o 2 ). The neighborhood-based distance, denoted d nb , is defined by It follows from the definition that d nb ((X 1 , o 1 ), (X 2 , o 2 )) = 0 for isomorphic (X 1 , o 1 ) and (X 2 , o 2 ) even if they are different. Therefore, d nb is not a metric but, as shown in [1], d nb is a pseudometric.

Radial Distribution Distance
Can we compute the neighborhood-based distance d nb efficiently? Note that an efficient algorithm for computing d nb could also be used to compute the Gromov-Hausdorff distance efficiently. However, as shown in [10,12], it is NP-hard to compute the Gromov-Hausdorff distance for finite metric spaces (see Proposition 3.16 in [12]). Moreover, under standard complexity-theoretic assumptions, there is no polynomial-time approximation algorithm with a reasonable factor for computing this distance [16].
In this section, we define another distance between rooted mm spaces called the radial distribution distance and denoted by d rd . On the one hand, d rd is coarser than d nb , more exactly, d rd is a lower bound on d nb . On the other hand, d rd can be computed efficiently: computing the radial distribution distance between finite rooted mm spaces takes time quasilinear in the total number of points.

Definition and Properties
Consider rooted mm spaces (X 1 , o 1 ) and (X 2 , o 2 ) where X 1 = (X 1 , d 1 , µ 1 ) and X 2 = (X 2 , d 2 , µ 2 ). To define the radial distribution distance between them, we first define the following functions m 1 and m 2 from [0, ∞) to itself: for every number r ∈ [0, ∞), That is, m 1 (r) is the measure (we could call it "mass" or "weight") of the ball of radius r around the origin o 1 and, similarly, for m 2 (r). The functions are nondecreasing and bounded. Also, m 1 and m 2 are càdlàg functions, i.e., they are right continuous with left limits, see Lemma 2.8 in [1]. Therefore, the distance function in the definition below is well defined.
Definition 5 (radial distribution distance). Let (X 1 , o 1 ) and (X 2 , o 2 ) be rooted mm spaces. The radial distribution distance, denoted d rd , is defined by We use the term "radial distribution distance" keeping in mind radial distribution functions from physics where they are used to measure the probability of finding a particle at distance r from a certain "origin" particle. In the setting of metric measure spaces, a radial distribution function describes how the total "mass" ("weight") of points at distance r from a center x changes when r increases. The radial distribution distance is basically a combination of the L 1 distance between the cumulative versions of the radial distribution functions and an exponential distance decay. Theorems 1 and 2 show basic properties of the radial distribution distance.
Proof. Let B r (o 1 ), B r (o 2 ), and δ r be the same as in Definition 4. Let µ 1 and µ 2 be the measures in X 1 and X 2 respectively. We prove the following inequality that implies claim (1): By the definition of the GHP distance, we have where f 1 and f 2 are arbitrary measurable isometries of the corresponding restrictions to an arbitrary mm space Y and π is the Lévy-Prokhorov distance in Y. By the definition of π, where γ is the infimum of all ǫ ≥ 0 such that Both inequalities above hold if we take and, therefore, we have Now, combining (3)- (5), we obtain inequality (2).

⊓ ⊔
The theorem above shows that d rd is a lower bound on d nb . This bound is strict, which can be seen from the following simple example. Consider a rooted mm space on a set of three points: {a, b, c} where a is the origin. The distance between any two points is 1. The measure assigned to each point is 1. Consider another rooted mm space that differs from the first one in only the measure of b and c: in the second space, the measure of b is 0.5 and the measure of c is 1.5. It is easy to see that the radial distribution distance between these spaces is 0, while the neighborhood distance is not zero.

Computing the Radial Distribution Distance
We describe a straightforward algorithm that computes the radial distribution distance between finite rooted mm spaces efficiently. In the description, we ignore all problems of numerical analysis and deal with real numbers. The algorithm is illustrated by applying it to the following example of two rooted mm spaces (X 1 , o 1 ) and (X 2 , o 2 ).  Example. We define (X 1 , o 1 ), where X 1 = (X 1 , d 1 , µ 1 ), using the graph on the left in Fig. 1: namely, X 1 = {v 1 , . . . , v 6 } and d 1 (v i , v j ) is the length of a shortest path between v i and v j . The measure µ 1 is defined by assigning numerical values to all one-element subsets of X 1 ; this assignment is shown in the second column of the table in Fig. 2. The origin o 1 is defined to be v 1 .
The rooted mm space (X 2 , o 2 ), where X 2 = (X 2 , d 2 , µ 2 ), is defined similarly using the graph on the right in Fig. 1. The underlying set X 2 consists of the vertices u 1 , . . . , u 6 with the shortest-path metric. The measure µ 2 is given by the forth column of the table in Fig. 2 and the origin o 2 is defined to be u 1 .
Algorithm. The radial distribution distance between finite rooted mm spaces can be computed using only part of information about the input spaces. The algorithm uses the distances between the origins and all other points; it does not use the distances between non-origin points. In terms of matrices, if a distance function in a rooted mm space with n points is represented by an n × n matrix, then the algorithm uses only one row (or column) corresponding to the origin. Therefore, we assume that the algorithm takes as input only the following: the distances between the origins and non-origins; -the measures of all one-element sets.
When the algorithm is applied to our example, it takes as input the table in Fig. 2.
6. Compute the radial distribution distance by Applying this to our example, we obtain Note that the algorithm takes O(n log n) steps where n is the number of points in the input spaces.
Considering the point v 1 in X 1 , what points in X 2 are most "similar" to v 1 and what points are most "dissimilar" to it? The calculations show that u 1 and u 6 are most similar to v 1 (with d rd ≈ 0.05), while the points u 3 and u 4 are most dissimilar to v 1 (with d rd ≈ 2.01).

Extension for Feature Vectors
The radial distribution distance d rd can be used to measure similarity between points in a metric space if points are described with a single feature: a value of this feature for a given point is viewed as the point's "weight". However, it is more typical that a point is described by a feature vector rather than a single feature. Each component of the vector corresponds to a measure on the metric space. For example, consider a recommender system for movies that uses item-item collaborative filtering. A metric on movies is based on the similarity between them calculated using people's ratings. In addition to the metric, each movie is described by a feature vector that can include, for example, the number of reviews, budget, box office, etc. [14] How can we compare points in a metric space if points are described using feature vectors? Suppose a feature vector consists of k components that correspond to measures µ 1 , . . . , µ k . Each measure µ i determines the radial distribution distance d The value d * rd ((X , x), (Y, y)) essentially shows the distance between the neighborhoods of x and y if we compare points by their feature vectors. Note that the sum of pseudometrics is also a pseudometric. Also note that instead of the sum in (6), we could take any other norm, for example, the Euclidean norm or the maximum.