Canberra Distance Calculator
Inputs
- Inputs: x = (4.00, 8.00, 15.00), y = (2.00, 8.00, 10.00).
- Each coordinate contributes |x - y| / (|x| + |y|): 0.3333, 0.0000 and 0.2000 - a term is 0 for identical values and 1 when one side is zero.
- Summing the three terms gives the Canberra distance: 0.3333 + 0.0000 + 0.2000 = 0.5333.
- Canberra distance: 0.5333 out of a maximum of 3.0000 for three coordinates - the per-coordinate normalisation makes it sensitive near zero, where plain Euclidean distance is not.
The Canberra distance compares two vectors coordinate by coordinate, scoring each gap as a fraction of the pair's combined magnitude on that coordinate. A difference of 2 matters enormously when the values are 4 and 2, and barely at all when the values are in the thousands - Canberra builds that intuition directly into the metric. Enter two vectors and the calculator sums the per-coordinate terms.
Lance and Williams proposed the measure in 1966 for ecological classification, where species counts span orders of magnitude and raw Euclidean distances are meaningless. It remains a standard choice whenever coordinates are non-negative quantities on wildly different scales.
Worked examples
One exact match, two relative gaps
(4 · 8 · 15 · 2 · 8 · 10)
| Canberra distance | 0.5333 |
| Mean per coordinate | 0.1778 |
| Largest single term | 0.3333 |
| Exact matches | 1 |
A presence-versus-absence coordinate
(10 · 0 · 3 · 5 · 4 · 3)
| Canberra distance | 1.3333 |
| Mean per coordinate | 0.4444 |
| Largest single term | 1.0000 |
| Exact matches | 1 |
Large values, small relative gaps
(100 · 200 · 50 · 90 · 220 · 50)
| Canberra distance | 0.1003 |
| Mean per coordinate | 0.0334 |
| Largest single term | 0.0526 |
| Exact matches | 1 |
A distance that rescales itself per coordinate
Each term divides the absolute gap by the sum of the two magnitudes, so every coordinate contributes a number between 0 and 1, whatever its scale. The first worked example compares (4, 8, 15) with (2, 8, 10): the terms are 0.3333, 0 and 0.2000, summing to a distance of 0.5333, with a mean term of 0.1778.
The zero term is the second coordinate, where both vectors hold 8: an exact match contributes nothing, and the calculator counts such coordinates separately - the first example has 1 of them.
The third example shows the scale-invariance at work. Vectors (100, 200, 50) and (90, 220, 50) differ by 10 on the first coordinate, yet that term is only 0.0526, the largest of a small set summing to 0.1003.
- Each coordinate term lies between 0 and 1; the total lies between 0 and the number of coordinates.
- A coordinate that is zero in both vectors contributes 0 by convention.
- The metric needs magnitudes, so it is designed for non-negative data.
Canberra against Euclidean and Manhattan
Euclidean distance is dominated by whichever coordinate has the largest absolute gaps - usually the one with the largest units. Manhattan distance has the same problem one degree milder. Canberra removes units from the comparison entirely: convert a coordinate from grams to kilograms and every term, hence the distance, is unchanged.
The price of that invariance is sensitivity near zero. The second example contains a coordinate that is 0 in one vector and 4 in the other: its term is the maximum possible, 1.0000, and the distance jumps to 1.3333. Near-zero coordinates with jitter can dominate a Canberra comparison just as surely as large coordinates dominate a Euclidean one.
In the second example that behaviour is arguably correct - presence versus absence is a real difference - but with noisy sensor data near zero it becomes a liability, and practitioners add a small offset or drop near-zero coordinates.
| Example | Distance | Mean term | Largest term | Exact matches |
|---|---|---|---|---|
| First | 0.5333 | 0.1778 | 0.3333 | 1 |
| Second | 1.3333 | 0.4444 | 1.0000 | 1 |
| Third | 0.1003 | 0.0334 | 0.0526 | 1 |
Worked examples
Example 1: x, coordinate 1 4; x, coordinate 2 8; x, coordinate 3 15; y, coordinate 1 2; y, coordinate 2 8; y, coordinate 3 10. Canberra distance = 0.5333. Supporting values: Mean per coordinate 0.1778; Largest single term 0.3333; Exact matches 1. Inputs: x = (4.00, 8.00, 15.00), y = (2.00, 8.00, 10.00). Each coordinate contributes |x - y| / (|x| + |y|): 0.3333, 0.0000 and 0.2000 - a term is 0 for identical values and 1 when one side is zero. Summing the three terms gives the Canberra distance: 0.3333 + 0.0000 + 0.2000 = 0.5333. Canberra distance: 0.5333 out of a maximum of 3.0000 for three coordinates - the per-coordinate normalisation makes it sensitive near zero, where plain Euclidean distance is not.
Example 2: x, coordinate 1 10; x, coordinate 2 0; x, coordinate 3 3; y, coordinate 1 5; y, coordinate 2 4; y, coordinate 3 3. Canberra distance = 1.3333. Supporting values: Mean per coordinate 0.4444; Largest single term 1.0000; Exact matches 1. Inputs: x = (10.00, 0.00, 3.00), y = (5.00, 4.00, 3.00). Each coordinate contributes |x - y| / (|x| + |y|): 0.3333, 1.0000 and 0.0000 - a term is 0 for identical values and 1 when one side is zero. Summing the three terms gives the Canberra distance: 0.3333 + 1.0000 + 0.0000 = 1.3333. Canberra distance: 1.3333 out of a maximum of 3.0000 for three coordinates - the per-coordinate normalisation makes it sensitive near zero, where plain Euclidean distance is not.
Example 3: x, coordinate 1 100; x, coordinate 2 200; x, coordinate 3 50; y, coordinate 1 90; y, coordinate 2 220; y, coordinate 3 50. Canberra distance = 0.1003. Supporting values: Mean per coordinate 0.0334; Largest single term 0.0526; Exact matches 1. Inputs: x = (100.00, 200.00, 50.00), y = (90.00, 220.00, 50.00). Each coordinate contributes |x - y| / (|x| + |y|): 0.0526, 0.0476 and 0.0000 - a term is 0 for identical values and 1 when one side is zero. Summing the three terms gives the Canberra distance: 0.0526 + 0.0476 + 0.0000 = 0.1003. Canberra distance: 0.1003 out of a maximum of 3.0000 for three coordinates - the per-coordinate normalisation makes it sensitive near zero, where plain Euclidean distance is not.
Zeros, signs and the empty-coordinate rule
The denominator of each term is the sum of absolute values, which keeps the term defined for any signs - but the classic interpretation assumes counts or amounts. With signed data, a coordinate of 5 in one vector and -5 in the other produces a term of 1 even though both magnitudes are large, which may or may not match the intended meaning.
The both-zero coordinate is the one genuine singularity: zero divided by zero. The universal convention, used here, is to count the term as 0 - two absences agree perfectly. Software that instead drops such coordinates silently changes the effective dimensionality, so check which convention any comparison tool applies.
Where Canberra is used today
The measure survives in ecology and microbiome studies, where abundance tables are its natural home, and in recommender and anomaly-detection work as a robust alternative when features are counts. It is implemented in standard scientific libraries, usually alongside the convention for zero coordinates described above.
It is less suited to dense continuous embeddings, where most coordinates are mid-range and the relative-gap logic adds little over standard metrics, and to data with meaningful negative values. Matching the metric to the data type matters more than the metric's elegance.
Reading a Canberra result
Start with the largest term: it names the coordinate driving the distance, which is often the actionable finding. Then the mean term tells you whether the difference is broad-based or concentrated. The first example's distance is one coordinate's story (0.3333 of the 0.5333 total); the second example's is a presence-absence story.
Enter both vectors at the same length and in the same coordinate order - the metric is meaningless under permutation. If your data can be negative, shift or transform it first and note that you did, because the choice changes the answer.
A side-by-side with Manhattan distance on the first example's vectors shows what the rescaling buys. Manhattan sums the raw gaps: 2 + 0 + 5 = 7, a number dominated by the third coordinate simply because its values are largest. Canberra's 0.5333 gives the first coordinate - a gap of 2 on values of 4 and 2, a fifty-percent disagreement - the largest single term, which matches how an ecologist would read the two sites: the proportional differences are the story, not the absolute ones.
In clustering pipelines Canberra pairs naturally with medoid-based methods, because it is not a squared-error geometry and has no meaningful centroid. Its terms also make it a diagnostic as much as a distance: the per-coordinate profile of a comparison - which coordinates contributed the 0.3333, which contributed nothing - is often reported alongside the total in ecological work, turning a similarity score into a list of the exact respects in which two samples differ. Few metrics hand you their own explanation like that.
A note on provenance rounds out the picture: the distance was designed for the classification problems of 1960s ecology, where a 'vector' was a site and its coordinates were species abundances, and the data's defining features - non-negative counts spanning orders of magnitude, with many zeros - are exactly the features the formula handles gracefully. Tools outlive their first jobs when their assumptions travel well. Before adopting Canberra for a new domain, check that your data shares those features; where it does, the measure's sixty-year track record is a reasonable promise, and where it does not, the failures will be the familiar ones - jitter near zero and meaningless signed coordinates.
FAQs
What distance does the first example give?
The first example gives a Canberra distance of 0.5333, from per-coordinate terms of 0.3333, 0 and 0.2000 across the three coordinates.
What is the mean term in the first example?
The mean term is 0.1778 in the first example - the distance divided by the three coordinates. It is the figure to use when comparing against distances from other dimensionalities.
What distance does the second example give?
The second example gives 1.3333. A coordinate that is 0 in one vector and 4 in the other contributes the maximum term of 1, which dominates the sum.
What is the largest term in the second example?
The largest term is 1.0000 in the second example - the presence-versus-absence coordinate. A single term can never exceed 1 in a Canberra sum.
What distance does the third example give?
The third example gives 0.1003. The vectors hold large values with modest relative gaps, so every term is small despite a raw difference of 10 on one coordinate.
What is the largest term in the third example?
The largest term is 0.0526 in the third example, from the 100-versus-90 coordinate. Even the biggest relative gap is small, which is why the total stays low.