View source: R/get_cardinalities.R
get_cardinalities | R Documentation |
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.
get_cardinalities(n_items, metric = c("footrule", "spearman", "ulam"))
n_items |
Number of items. |
metric |
Distance function, one of "footrule", "spearman", or "ulam". |
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}
.
Other partition function:
compute_exact_partition_function()
,
estimate_partition_function()
# 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))))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.