-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompute_sequentially.Rd
More file actions
161 lines (141 loc) · 5.06 KB
/
compute_sequentially.Rd
File metadata and controls
161 lines (141 loc) · 5.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/compute_sequentially.R
\name{compute_sequentially}
\alias{compute_sequentially}
\title{Compute the Bayesian Mallows model sequentially}
\usage{
compute_sequentially(
data,
hyperparameters = set_hyperparameters(),
smc_options = set_smc_options(),
topological_sorts = NULL
)
}
\arguments{
\item{data}{A dataframe containing partial rankings or pairwise preferences.
If \code{data} contains complete or partial rankings, it must have the following
columns:
\itemize{
\item \code{timepoint}: a numeric vector denoting the timepoint, starting at 1.
\item \code{user}: a vector identifying the user.
\item \code{item1}: ranking of item 1.
\item \code{item2}: ranking of item 2.
\item etc.
}
If data contains pairwise preferences, it must have the following
structure:
\itemize{
\item \code{timepoint}: a numeric vector denoting the timepoint, starting at 1.
\item \code{user}: a vector identifying the user.
\item \code{top_item}: identifier for the preferred item.
\item \code{bottom_item}: identifier for the dispreferred item.
}}
\item{hyperparameters}{A list returned from \code{\link[=set_hyperparameters]{set_hyperparameters()}}.}
\item{smc_options}{A list returned from \code{\link[=set_smc_options]{set_smc_options()}}. Controls the
nested SMC2 algorithm parameters including number of parameter particles,
number of particle filters per parameter particle, and MCMC move parameters.}
\item{topological_sorts}{A list returned from
\code{\link[=precompute_topological_sorts]{precompute_topological_sorts()}}. Only used with preference data, and
defaults to \code{NULL}. Contains precomputed topological sorts for efficient
sampling from constrained ranking spaces.}
}
\value{
An object of class BayesMallowsSMC2 containing posterior samples
and algorithm diagnostics.
}
\description{
This function implements the nested sequential Monte Carlo (SMC2) algorithm
for sequential learning of rank and preference data using the Bayesian
Mallows model. The algorithm processes data sequentially over time,
maintaining a particle approximation to the posterior distribution.
}
\details{
The nested SMC2 algorithm consists of two levels of sequential Monte Carlo:
\strong{Outer SMC (Parameter Level)}: Maintains particles representing samples
from the posterior distribution of static parameters (alpha, rho, tau).
Each particle contains its own set of parameter values.
\strong{Inner SMC (Latent State Level)}: For each parameter particle, maintains
multiple particle filters that track the evolution of latent rankings and
cluster assignments over time. This nested structure allows the algorithm
to handle the complex dependency structure between parameters and latent
states.
At each timepoint, the algorithm:
\enumerate{
\item Propagates each parameter particle forward using MCMC moves
\item For each parameter particle, runs multiple particle filters to sample
latent rankings and cluster assignments
\item Computes importance weights based on the likelihood of observed data
\item Resamples particles when effective sample size drops below threshold
\item Applies rejuvenation moves to maintain particle diversity
}
The nested structure is essential for maintaining proper uncertainty
quantification in the joint parameter-latent state space.
}
\examples{
# Example with complete rankings
library(BayesMallowsSMC2)
# Generate synthetic ranking data
set.seed(123)
n_items <- 5
n_users <- 20
n_timepoints <- 10
# Create synthetic data
data <- expand.grid(
timepoint = 1:n_timepoints,
user = 1:n_users
)
# Add random rankings for each item
for(i in 1:n_items) {
data[[paste0("item", i)]] <- sample(1:n_items, nrow(data), replace = TRUE)
}
# Set hyperparameters
hyperparams <- set_hyperparameters(
n_items = n_items,
alpha_shape = 2,
alpha_rate = 1,
n_clusters = 2
)
# Set SMC options
smc_opts <- set_smc_options(
n_particles = 100,
n_particle_filters = 20,
metric = "kendall",
verbose = TRUE
)
# Run sequential computation
result <- compute_sequentially(
data = data,
hyperparameters = hyperparams,
smc_options = smc_opts
)
# Example with pairwise preferences
# First precompute topological sorts
prefs_matrix <- matrix(c(1, 2, 2, 3, 3, 1), ncol = 2, byrow = TRUE)
topo_sorts <- precompute_topological_sorts(
prefs = prefs_matrix,
n_items = 3,
save_frac = 0.1
)
# Create preference data
pref_data <- data.frame(
timepoint = c(1, 1, 2, 2),
user = c(1, 2, 1, 2),
top_item = c(1, 2, 3, 1),
bottom_item = c(2, 3, 1, 3)
)
# Run with preferences
result_prefs <- compute_sequentially(
data = pref_data,
hyperparameters = set_hyperparameters(n_items = 3),
smc_options = set_smc_options(n_particles = 50),
topological_sorts = topo_sorts
)
}
\references{
Sørensen, Ø., Stein, A., Netto, W. L., & Leslie, D. S. (2025).
Sequential Rank and Preference Learning with the Bayesian Mallows Model.
\emph{Bayesian Analysis}. DOI: 10.1214/25-BA1564.
}
\seealso{
\code{\link[=set_hyperparameters]{set_hyperparameters()}}, \code{\link[=set_smc_options]{set_smc_options()}}, \code{\link[=precompute_topological_sorts]{precompute_topological_sorts()}}
}