AI Glossary / Causal inference and experimentation / Intermediate

Metric space

Definition

A metric space is a set of objects together with a distance function that satisfies four rules: nonnegativity, zero distance exactly for identical objects, symmetry, and the triangle inequality. The function makes ideas such as closeness and neighborhood precise. In machine learning, objects might be feature vectors, strings, or graph nodes. This mathematical meaning of metric is narrower than the everyday evaluation meaning of a score used to assess performance.

What it means

Distance is not automatically defined just because objects are represented as data. Two customer profiles, documents, or routes can be compared in different ways, and the chosen comparison determines which pairs count as close.

A metric space combines the objects and the distance rule into one mathematical setting. The same collection equipped with different valid distances can have different nearest neighbors and cluster patterns. Satisfying the metric rules makes the distance mathematically well behaved, but it does not prove the chosen distance captures the similarity that matters for a business or scientific task. Representation and interpretation still require judgment.

How it works

For objects x and y, a metric d(x,y) is never negative. It equals zero if and only if x and y are the same object in the defined set. It is symmetric: reversing the pair does not change the distance.

For any third object z, the triangle inequality requires d(x,z) ≤ d(x,y) + d(y,z). Going through an intermediate object cannot make the direct metric distance larger than that sum.

Once the distance is defined, a neighborhood can contain objects within a selected radius. Algorithms can use distances for nearest-neighbor retrieval, clustering, or other calculations. Some computational methods rely on metric properties, so replacing the distance with an arbitrary similarity or dissimilarity score may invalidate their assumptions.

Three practical examples

1. Feature-vector search: a system finds nearby vectors under Euclidean distance, with feature scaling chosen to make the comparison meaningful.

2. String comparison: a spelling tool uses an appropriate edit-distance definition to compare how many permitted edits separate candidate words.

3. Network analysis: connected nodes in an undirected graph can be compared by shortest-path length, giving a distance based on the graph's links rather than geometric coordinates.

Think of it this way

Think of a map where a distance rule consistently tells how far every pair of places is apart. The triangle inequality says a direct distance cannot exceed traveling through a third place under that same rule. The analogy is limited: many data objects are not physical locations, and one-way travel times can be asymmetric. Such useful quantities do not necessarily form a metric without modification.

Worked example

Take three points A = (0,0), B = (3,0), and C = (3,4). Under Euclidean distance, d(A,B) = 3, d(B,C) = 4, and d(A,C) = 5. The triangle inequality holds because 5 ≤ 3 + 4.

Under Manhattan distance, which adds absolute coordinate differences, the same pair A and C has distance 3 + 4 = 7. Both distance rules are metrics, but they express different geometry.

Now consider squared Euclidean distance on the real-number points 0, 1, and 2. The direct value from 0 to 2 is 4, while the two-step sum is 1 + 1 = 2. Since 4 ≤ 2 is false, squared Euclidean distance is not itself a metric, despite being useful in many learning objectives.

Illustrative case study

Fictional case: Birch Match retrieves products using two numeric features measured on very different scales. Euclidean distance is mathematically valid, but the large-scale feature dominates which products appear nearest. Staff notice that the retrieved products do not reflect the intended comparison.

The team revisits feature units and scaling, then evaluates candidate distances using representative relevance judgments. It also checks whether its search implementation relies on the triangle inequality before substituting another dissimilarity measure. The case distinguishes two separate questions: whether a function is a metric, and whether its notion of closeness is useful for the task.

Common misconceptions and mistakes

Do not assume every function called a distance in software satisfies all metric axioms. Names often reflect practical usage rather than a mathematical guarantee.

Do not confuse a metric space with a vector space. A collection can have a valid distance without supporting vector addition or scalar multiplication.

Avoid treating zero feature distance as proof that two real-world entities are identical. If distinct entities share the same representation, the induced distance may be a pseudometric on the entities even though it is a metric on the feature vectors. Specify which objects constitute the set.

Business use

Metric-space reasoning helps teams assess whether a similarity-based method matches its algorithmic assumptions. It is relevant to retrieval, clustering, deduplication, and geometric representations, where distance choices influence what the system groups or recommends.

Document the objects, representation, units, distance formula, and any scaling. Test practical relevance separately from the mathematical properties. When changing a distance, consider whether existing indexes, thresholds, or neighborhood interpretations remain valid. A smaller distance is only meaningful relative to the chosen rule; it is not automatically a better business match, a causal relationship, or a calibrated probability.

People also ask

Must a metric space contain numerical vectors?

No. Its elements can be other objects, provided a distance satisfying the metric rules is defined on the set.

Is squared Euclidean distance a metric?

Generally no, because it can violate the triangle inequality, as the three-point example demonstrates.

Does a valid metric guarantee useful clusters?

No. Cluster usefulness also depends on the representation, distance choice, data, and intended task. Mathematical validity is a separate issue.

Check your understanding

A proposed comparison gives d(A,B) = 2 and d(B,A) = 5. Can it be a metric on these objects?

Answer: No. It violates symmetry. The comparison may still be useful for a directional task, but it does not satisfy the ordinary metric definition.

Related terms

  • Metric
  • Euclidean distance
  • Manhattan distance
  • Triangle inequality
  • Norm
  • Nearest neighbor
  • Feature space
  • distance function
  • pseudometric

Learn next

Choose three simple objects and calculate all pairwise distances under a proposed rule. Check the four metric properties, then ask whether the resulting nearest pairs make sense for the task. Repeat with a different scaling or distance to separate mathematical validity from practical relevance.

  • Metric

More in Causal inference and experimentation

  • Longitudinal targeted maximum likelihood estimation - Longitudinal targeted maximum likelihood estimation, or LTMLE, is a framework for estimating specified causal quantities from data containing treatment...
  • Max error - Max error is the largest absolute difference between a prediction and its observed target in an evaluated dataset.
  • METEOR - METEOR is an automatic text-evaluation metric developed for machine translation.
  • Minimax loss - Minimax loss, in the supplied glossary's generative-adversarial-network context, is the original GAN objective that a generator tries to minimize while a...
  • Mixed Precision - Mixed precision is the use of more than one numerical precision within a computation.
  • Mixture experiment - A mixture experiment studies how the proportions of components in a blend affect a measured response.

Sources

Primary source: Aalto Dictionary of Machine Learning, metric space, https://aaltodictionaryofml.github.io/ADictML_Main.pdf . The four axioms and examples were consulted. The supplied evaluation category is retained, while the entry explicitly describes the mathematical distance-space meaning. Coordinates, the squared-distance counterexample, and the fictional retrieval project are original teaching illustrations.

Previous: Metric multidimensional scaling Next: Metrology study

  • Home
  • Daily AI Updates
  • Blog
  • AIFBL Academy
  • AI Glossary
  • Products and Tools
  • Store
  • Free CFO AI Prompt Pack
  • About Shihan Sheriff
  • Privacy Policy
  • Terms of Use
  • Refund Policy
  • Cookie Policy
  • Earnings Disclaimer