category

similarity_metric_common

Shared helper predicates for sparse-vector overlap, numeric scaling, normalization, and correlation, reused by the library similarity metric objects.

Availability:
logtalk_load(recommender_protocols(loader))
Author: Paulo Moura
Version: 1:0:0
Date: 2026-10-07
Compilation flags:
static
Remarks:
(none)
Inherited public predicates:
(none)

Public predicates

(no local declarations; see entity ancestors if any)

Protected predicates

common_pairs/3

Collects the Value1-Value2 pairs for the keys present in both sparse vectors. Assumes each vector declares at most one value per key.

Compilation flags:
static
Template:
common_pairs(Vector1,Vector2,Pairs)
Mode and number of proofs:
common_pairs(+list(pair),+list(pair),-list(pair)) - one

vector_norm/2

Computes the Euclidean norm of the values of a sparse Key-Value vector.

Compilation flags:
static
Template:
vector_norm(Vector,Norm)
Mode and number of proofs:
vector_norm(+list(pair),-float) - one

scale_values/2

Scales numeric values by their maximum absolute magnitude, leaving empty and all-zero lists unchanged.

Compilation flags:
static
Template:
scale_values(Values,Scaled)
Mode and number of proofs:
scale_values(+list(number),-list(number)) - one

normalize_values/2

Unit-normalizes numeric values using bounded intermediate magnitudes, leaving empty and all-zero lists unchanged.

Compilation flags:
static
Template:
normalize_values(Values,Normalized)
Mode and number of proofs:
normalize_values(+list(number),-list(number)) - one

normalize_vector/2

Unit-normalizes a sparse numeric vector while preserving its keys and their order.

Compilation flags:
static
Template:
normalize_vector(Vector,Normalized)
Mode and number of proofs:
normalize_vector(+list(pair),-list(pair)) - one

bounded_similarity/2

Bounds a computed cosine or correlation score to its mathematical range, removing endpoint roundoff.

Compilation flags:
static
Template:
bounded_similarity(Score,Similarity)
Mode and number of proofs:
bounded_similarity(+number,-number) - one

centered_normalized_values/2

Centers and unit-normalizes numeric values in shifted, scaled coordinates. Empty lists remain empty and exactly constant lists become zeros.

Compilation flags:
static
Template:
centered_normalized_values(Values,Normalized)
Mode and number of proofs:
centered_normalized_values(+list(number),-list(number)) - one

split_pairs/3

Splits a list of Value1-Value2 pairs into separate, position-aligned lists of first and second values.

Compilation flags:
static
Template:
split_pairs(Pairs,Values1,Values2)
Mode and number of proofs:
split_pairs(+list(pair),-list(number),-list(number)) - one

dot_product/3

Computes the dot product of two position-aligned numeric lists of the same length.

Compilation flags:
static
Template:
dot_product(Values1,Values2,Dot)
Mode and number of proofs:
dot_product(+list(number),+list(number),-number) - one

sum_of_squares_list/2

Computes the sum of the squares of a numeric list.

Compilation flags:
static
Template:
sum_of_squares_list(Values,SumSquares)
Mode and number of proofs:
sum_of_squares_list(+list(number),-number) - one

mean_values/2

Computes the arithmetic mean of a non-empty numeric list.

Compilation flags:
static
Template:
mean_values(Values,Mean)
Mode and number of proofs:
mean_values(+list(number),-float) - one_or_error
Exceptions:
Values is empty:
evaluation_error(zero_divisor)

center/3

Subtracts a value (typically the mean) from every element of a numeric list.

Compilation flags:
static
Template:
center(Values,Value,Centered)
Mode and number of proofs:
center(+list(number),+number,-list(number)) - one

Private predicates

(no local declarations; see entity ancestors if any)

Operators

(none)