viva_glyph/metrics

Metrics - Mathematical operations for Glyph comparison

Leverages gleam_community_maths for distance and similarity metrics between Glyphs and PAD states.

Distance Metrics

Use Cases

Types

Statistical summary of a list of Glyphs

pub type GlyphStats {
  GlyphStats(count: Int, mean: List(Float), std_dev: List(Float))
}

Constructors

  • GlyphStats(count: Int, mean: List(Float), std_dev: List(Float))

    Arguments

    count

    Number of glyphs

    mean

    Mean vector (centroid)

    std_dev

    Standard deviation per dimension

Values

pub fn entropy(probs: List(Float)) -> Float

Entropy of a probability distribution H = -Σ p × ln(p)

pub fn exp(x: Float) -> Float

Exponential function e^x

pub fn glyph_cosine(a: glyph.Glyph, b: glyph.Glyph) -> Float

Cosine similarity between Glyphs [−1, 1]

pub fn glyph_euclidean(a: glyph.Glyph, b: glyph.Glyph) -> Float

Euclidean distance between two Glyphs

pub fn glyph_manhattan(a: glyph.Glyph, b: glyph.Glyph) -> Float

Manhattan distance between Glyphs

pub fn glyph_norm(g: glyph.Glyph) -> Float

L2 norm of Glyph vector

pub fn glyph_stats(glyphs: List(glyph.Glyph)) -> GlyphStats

Calculate statistics for a collection of Glyphs

pub fn glyph_to_vector(g: glyph.Glyph) -> List(Float)

Convert Glyph tokens to normalized vector [0, 1]

pub fn ln(x: Float) -> Result(Float, Nil)

Natural logarithm (wrapper for use in other modules)

pub fn pad_cosine(a: encoder.Pad, b: encoder.Pad) -> Float

Cosine similarity between PAD states [−1, 1] 1.0 = same direction, 0.0 = orthogonal, −1.0 = opposite

pub fn pad_euclidean(a: encoder.Pad, b: encoder.Pad) -> Float

Euclidean distance between two PAD states Returns L2 norm of difference: sqrt(Σ(a-b)²)

pub fn pad_manhattan(a: encoder.Pad, b: encoder.Pad) -> Float

Manhattan distance between PAD states Returns L1 norm: Σ|a-b|

pub fn pad_norm(pad: encoder.Pad) -> Float

L2 norm (magnitude) of PAD vector

pub fn pad_to_vector(pad: encoder.Pad) -> List(Float)

Convert PAD to normalized vector [0, 1]

pub fn softmax(values: List(Float)) -> List(Float)

Softmax over a list of values Returns probability distribution that sums to 1.0

Search Document