Distance
A distance function assigns a numerical measure of separation or dissimilarity to pairs of points or objects in a defined space.
Data Without Labels
A distance metric is a distance function that satisfies the metric-space properties, including nonnegativity, symmetry, and the triangle inequality.
- How it is used
- Measures similarity for clustering and helps determine centroid assignments, hierarchical merges, and DBSCAN neighborhoods.
- How deep it goes
- Defines three distance measures with coordinate formulas and applies them in clustering workflows, without developing formal metric-space properties.
- Examples
- Uses two-point coordinate formulas, visual distance comparisons, and SciPy dendrograms with varied linkage rules and cutoffs.
- What you can do after
- Apply it via SciPy hierarchical clustering to compare distance settings and linkage rules, then inspect how a cutoff changes the groups.
Advanced Algorithms and Data Structures
A distance function is a function that assigns a path-cost contribution or distance value to an edge or other argument.
- How it is used
- Supplies comparison values for nearest-neighbor search and clustering, or edge-cost contributions for graph pathfinding.
- How deep it goes
- Works through threshold tests and A* parameter choices, while distinguishing Euclidean requirements from an SS-tree’s more general metric requirements.
- Examples
- Uses warehouse selection, price-and-rating points, canopy thresholds, SS-tree bounding spheres, and weighted versus unit-cost graph edges.
- What you can do after
- Apply it via nearest-neighbor queries, clustering thresholds, SS-tree sphere tests, or an A* edge-cost argument.
Read how Advanced Algorithms and Data Structures explains distance →
Outlier Detection in Python
A function that quantifies dissimilarity or separation between observations in a data space.
- How it is used
- Uses pairwise separation to identify unusual records and represent divergence between related time series.
- How deep it goes
- Compares several distance measures and mixed-data weighting, while cautioning that high dimensionality can undermine distance-based detection.
- Examples
- Illustrates a four-dimensional point unusual in one feature and air-quality series compared through pairwise differences.
- What you can do after
- Evaluate/understand it: compare distance measures and recognize when scaling, mixed-data choices, or dimensionality may affect results.
Natural Language Processing in Action, Second Edition
A distance metric is a function that quantifies dissimilarity between objects while satisfying the mathematical properties of a metric.
- How it is used
- Uses distances between text and feature vectors to compare documents, assess topic representations, and support tasks such as spelling correction.
- How deep it goes
- Names common distance measures and explains vector comparisons, noting that LSA may lose fine-grained proximity.
- Examples
- Contrasts “good” with “okay” and “bad” with “bag,” then compares LSA topic-vector distances with TF–IDF distances.
- What you can do after
- Evaluate whether topic vectors retain document relationships by comparing their distances with those in a higher-dimensional TF–IDF representation.
Read how Natural Language Processing in Action, Second Edition explains distance →
Build an Advanced RAG Application (From Scratch)
A distance metric is a function that quantifies proximity or dissimilarity between points or vectors in a mathematical space.
- How it is used
- Ranks hotel reviews in a semantic-search pipeline by comparing query and document embeddings.
- How deep it goes
- Defines cosine and Euclidean distance, then implements cosine ranking with normalization and top-k selection.
- Examples
- Uses a Paris hotel query, review embeddings, ranked hotel reviews, and printed similarity scores.
- What you can do after
- Apply it via NumPy to rank embedded documents and inspect the highest-scoring semantic matches.
Read how Build an Advanced RAG Application (From Scratch) explains distance →
Math for Web Design
Distance is a numerical measure of the separation between two points or geometric objects.
- How it is used
- Controls hover intensity, click animations, pinch zoom, and radial hit detection through measured separation between points.
- How deep it goes
- Works through Pythagorean calculations and their use in event-driven UI code, including normalization, thresholds, and radius checks.
- Examples
- Uses a geometric hover effect, a click-following dot, a pinch-zoomed photo, and an interactive donut chart.
- What you can do after
- Apply it via JavaScript distance calculations to set UI scale, animation stopping points, and curved-chart hit bounds.
Architecture Modernization: Socio-technical alignment of software, strategy, and structure
Distance is the amount of technical and organizational coordination required for related parts to implement a change together.
- How it is used
- Assess the coordination cost of coupling as one factor in estimating its overall pain.
- How deep it goes
- Defines organizational and technical distance and illustrates a scale from variables in one function to separate microservices.
- Examples
- Contrasts variables in one function with classes across codebases, and teams with differing managers or office locations.
- What you can do after
- Evaluate coupling costs by assessing coordination distance alongside strength and volatility.
Geometry for Programmers
Distance is a nonnegative measure of separation between points or between a point and a geometric set.
- How it is used
- Deploys scalar distance fields to describe geometric separation, planes, segments, rectangles, and enclosed shapes.
- How deep it goes
- Explains geometric derivations and Python implementations for points, lines, segments, planes, and rectangles, stopping short of mesh-wide construction.
- Examples
- Uses point-to-plane geometry, a disk SDF, point-to-point and point-to-segment Python functions, and a rectangular SDF.
- What you can do after
- Build it from scratch using vector products, projections, endpoint tests, and edge signs to compute basic distance fields.
Machine Learning Platform Engineering
A distance metric is a function that quantifies separation between vectors in a mathematical space.
- How it is used
- Uses vector distances to find chunks near a query vector during RAG retrieval.
- How deep it goes
- Names L2, cosine, and inner product, and explains cosine’s focus on semantic direction without deriving the metrics.
- Examples
- Uses a query vector and nearby document-chunk vectors to illustrate retrieval, and contrasts cosine with magnitude-sensitive comparison.
- What you can do after
- Evaluate retrieval choices by considering supported distance metrics and cosine’s emphasis on semantic direction.
Read how Machine Learning Platform Engineering explains distance →
Build AI Drug Discovery Pipelines
Distance is a numerical measure of separation between two points or objects in a mathematical representation.
- How it is used
- Uses separation between feature-space points to compare molecules and select representative, diverse samples.
- How deep it goes
- Defines distance through coordinates and explains pairwise calculations and Kennard–Stone selection, while noting high-dimensional challenges.
- Examples
- Illustrates coordinates with an apple and orange, and sample selection with ligand descriptors and a toy dataset.
- What you can do after
- Apply it via the Kennard–Stone algorithm to select a diverse subset from a dataset.
Read how Build AI Drug Discovery Pipelines explains distance →
Classic Computer Science Problems in Swift: Essential techniques for practicing programmers
A measure of separation between locations or points in a feature space.
- How it is used
- Tracks accumulated route costs to find shortest paths from a starting vertex through a weighted graph.
- How deep it goes
- Explains initialization, priority-queue exploration, and shorter-route updates through a Swift implementation.
- Examples
- Uses a city graph to calculate distances from Los Angeles and trace a route to Boston.
- What you can do after
- Apply Dijkstra’s algorithm to compute shortest distances and recover paths in a weighted graph.
Machine Learning System Design
A function that assigns a numerical measure of separation or dissimilarity between mathematical objects or representations.
- How it is used
- Combines retrieval distances and other signals into a unified relevance score for photo search.
- How deep it goes
- Contrasts a simple sum with a weighted sum, but does not detail how to choose or train the weights.
- Examples
- Combines query-to-image and query-to-description distances with user and document features in a photo-search score.
- What you can do after
- Evaluate whether a simple sum or weighted sum should combine retrieval distances and other features.
Also covered in
- Causal Inference for Data Science
- Web Components in Action
- AI Agents and Applications
- Grokking Algorithms, Second Edition
- Deep Learning with R, Third Edition
- Just Use Postgres!
- Machines that ThinkIn early access (MEAP)
- Snowflake Data Engineering
- Grokking Machine Learning, Second EditionIn early access (MEAP)
- Generative AI in Action
- Cyber Threat Hunting
- Latency
What to know first
- Euclidean distanceEuclidean distance is the straight-line distance between two points, calculated as the square root of the sum of squared differences between corresponding coordinates.
- linear regressionLinear regression is a statistical method that models a numeric response as a linear function of one or more predictor variables with fitted parameters.
- meanThe mean is a measure of central location equal to the arithmetic average of numerical observations, or the probability-weighted average of a random variable’s possible values.
- inner productAn inner product is a scalar-valued operation on two vectors that generalizes the dot product, which for real coordinate vectors is the sum of products of corresponding components.
Related concepts
- mahalanobis distanceincludes · Mahalanobis distance is a covariance-adjusted measure of separation between observations or between an observation and a reference distribution.
- chebyshev distanceincludes · Chebyshev distance is the maximum absolute difference between corresponding coordinates of two points.
Questions about distance
What is distance?
A distance function assigns a numerical measure of separation or dissimilarity to pairs of points or objects in a defined space.
Which Manning books explain distance?
Data Without Labels, Advanced Algorithms and Data Structures, Outlier Detection in Python, Natural Language Processing in Action, Second Edition, Build an Advanced RAG Application (From Scratch), Math for Web Design, Architecture Modernization: Socio-technical alignment of software, strategy, and structure, Geometry for Programmers and 4 more.
What should I know before learning distance?
Manning books that teach distance usually introduce Euclidean distance, linear regression, mean and inner product first.
What kinds of distance are there?
Kinds of distance include mahalanobis distance, angular distance and chebyshev distance.
What is distance part of?
Distance is part of pain. Pain is a measure of the cost of a particular coupling instance, calculated as the product of its strength, volatility, and distance.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.











