Skip to content
DistanceMetric

DistanceMetric

Mojo struct 🡭

DistanceMetric

@memory_only
struct DistanceMetric

How far apart two rows are.

The choice changes what “similar” means, and it changes the answer: EUCLIDEAN groups rows whose values are close, CORRELATION groups rows whose values move together whatever their level, which is usually what is wanted when the rows are measured in different units or at different baselines.

Aliases

  • EUCLIDEAN = DistanceMetric(Int(0)): Straight-line distance: sqrt(sum((a - b)^2)).
  • CITYBLOCK = DistanceMetric(Int(1)): Sum of absolute differences, less swayed by one large gap.
  • CORRELATION = DistanceMetric(Int(2)): 1 - r, for Pearson’s r: two rows that rise and fall together are close however far apart their levels are. A row with no variation has no correlation with anything, and is treated as maximally distant (1.0) from every other row rather than left undefined.

Implemented traits

AnyType, Copyable, Deinitable, ImplicitlyCopyable, Movable

Methods

__init__

fn def __init__(out self, value: Int)

Construct from the integer tag.

Args:

  • value (Int): The tag.
  • self (Self)

Returns:

Self

__eq__

fn def __eq__(self, other: Self) -> Bool

Whether two metrics are the same.

Args:

  • self (Self)
  • other (Self): The metric to compare with.

Returns:

Bool: True when they match.