get_cardinalities: Get cardinalities for each distance

View source: R/get_cardinalities.R

get_cardinalitiesR Documentation

Get cardinalities for each distance

Description

The partition function for the Mallows model can be defined in a computationally efficient manner as

Z_{n}(\alpha) = \sum_{d_{n} \in \mathcal{D}_{n}} N_{m,n} e^{-(\alpha/n) d_{m}}.

In this equation, \mathcal{D}_{n} a set containing all possible distances at the given number of items, and d_{m} is on element of this set. Finally, N_{m,n} is the number of possible configurations of the items that give the particular distance. See \insertCiteirurozki2016;textualBayesMallows, \insertCitevitelli2018;textualBayesMallows, and \insertCitecrispino2023;textualBayesMallows for details.

For footrule distance, the cardinalities come from entry A062869 in the On-Line Encyclopedia of Integer Sequences (OEIS) \insertCiteoeisBayesMallows. For Spearman distance, they come from entry A175929, and for Ulam distance from entry A126065.

Usage

get_cardinalities(n_items, metric = c("footrule", "spearman", "ulam"))

Arguments

n_items

Number of items.

metric

Distance function, one of "footrule", "spearman", or "ulam".

Value

A dataframe with two columns, distance which contains each distance in the support set at the current number of items, i.e., d_{m}, and value which contains the number of values at this particular distances, i.e., N_{m,n}.

References

\insertAllCited

See Also

Other partition function: compute_exact_partition_function(), estimate_partition_function()

Examples

# Extract the cardinalities for four items with footrule distance
n_items <- 4
dat <- get_cardinalities(n_items)
# Compute the partition function at alpha = 2
alpha <- 2
sum(dat$value * exp(-alpha / n_items * dat$distance))
#'
# We can confirm that it is correct by enumerating all possible combinations
all <- expand.grid(1:4, 1:4, 1:4, 1:4)
perms <- all[apply(all, 1, function(x) length(unique(x)) == 4), ]
sum(apply(perms, 1, function(x) exp(-alpha / n_items * sum(abs(x - 1:4)))))

# We do the same for the Spearman distance
dat <- get_cardinalities(n_items, metric = "spearman")
sum(dat$value * exp(-alpha / n_items * dat$distance))
#'
# We can confirm that it is correct by enumerating all possible combinations
sum(apply(perms, 1, function(x) exp(-alpha / n_items * sum((x - 1:4)^2))))

BayesMallows documentation built on Sept. 11, 2024, 5:31 p.m.