Distance
Distance is a measure of separation between points or entities in a defined space or context.
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 →
Math for Web Design
Distance is a numerical measure of the separation between two points or geometric objects.
- How it is used
- Drives pointer, touch, animation, and canvas interactions by measuring separation between coordinates.
- How deep it goes
- Explains Pythagorean calculations and applies normalized, clamped, and radius-bounded distances in JavaScript.
- Examples
- Uses hover tilt, a click-chaser dot, photo pinch zoom, and donut-chart slice hit detection.
- What you can do after
- Apply it via JavaScript to normalize hover effects, animate toward targets, scale touch content, and test radial 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 →
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.
Related concepts
- mahalanobis distanceincludes · Mahalanobis distance is a covariance-adjusted measure of separation between observations or between an observation and a reference distribution.
- Euclidean distanceincludes · Euclidean distance is the straight-line distance between two points in Euclidean space, calculated as the square root of the sum of squared differences between corresponding coordinates.
- similarity metricmeasures · A similarity measure is a rule that quantifies or characterizes how alike two objects or representations are according to selected properties.
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.









