Skip to content

Commit be7a820

Browse files
docs: add CRAN-compliant documentation with examples for exported functions
Co-authored-by: aider (anthropic/claude-sonnet-4-20250514) <aider@aider.chat>
1 parent 80fd02a commit be7a820

File tree

2 files changed

+93
-28
lines changed

2 files changed

+93
-28
lines changed

R/set_hyperparameters.R

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,41 @@
1-
#' Set hyperparameters
1+
#' Set hyperparameters for Bayesian Mallows model
22
#'
3-
#' @param n_items Integer defining the number of items.
4-
#' @param alpha_shape Shape of gamma prior for alpha.
5-
#' @param alpha_rate Rate of gamma prior for alpha.
6-
#' @param cluster_concentration Concentration parameter of Dirichlet distribution for cluster probabilities.
7-
#' @param n_clusters Integer defining the number of clusters.
3+
#' This function creates a list of hyperparameters for the Bayesian Mallows model
4+
#' used in sequential Monte Carlo inference. The hyperparameters define the prior
5+
#' distributions for the model parameters.
86
#'
9-
#' @return A list
7+
#' @param n_items Integer defining the number of items to be ranked. Must be a
8+
#' positive integer.
9+
#' @param alpha_shape Positive numeric value specifying the shape parameter of
10+
#' the gamma prior distribution for the scale parameter alpha. Default is 1.
11+
#' @param alpha_rate Positive numeric value specifying the rate parameter of
12+
#' the gamma prior distribution for the scale parameter alpha. Default is 0.5.
13+
#' @param cluster_concentration Positive numeric value specifying the
14+
#' concentration parameter of the Dirichlet distribution for cluster
15+
#' probabilities. Default is 10.
16+
#' @param n_clusters Positive integer defining the number of clusters in the
17+
#' mixture model. Default is 1.
18+
#'
19+
#' @return A list containing the hyperparameter values with elements:
20+
#' \item{n_items}{Number of items}
21+
#' \item{alpha_shape}{Shape parameter for alpha prior}
22+
#' \item{alpha_rate}{Rate parameter for alpha prior}
23+
#' \item{cluster_concentration}{Concentration parameter for cluster probabilities}
24+
#' \item{n_clusters}{Number of clusters}
25+
#'
26+
#' @examples
27+
#' # Basic hyperparameters for 5 items
28+
#' hyper <- set_hyperparameters(n_items = 5)
29+
#'
30+
#' # Custom hyperparameters with multiple clusters
31+
#' hyper <- set_hyperparameters(
32+
#' n_items = 10,
33+
#' alpha_shape = 2,
34+
#' alpha_rate = 1,
35+
#' cluster_concentration = 5,
36+
#' n_clusters = 3
37+
#' )
38+
#'
1039
#' @export
1140
#'
1241
set_hyperparameters <- function(

R/set_smc_options.R

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,62 @@
1-
#' Set SMC options
1+
#' Set SMC options for sequential inference
22
#'
3-
#' @param n_particles Number of particles
4-
#' @param n_particle_filters Initial number of particle filters for each
5-
#' particle
6-
#' @param max_particle_filters Maximum number of particle filters.
7-
#' @param resampling_threshold Effective sample size threshold for resampling
8-
#' @param doubling_threshold Threshold for particle filter doubling. If the
9-
#' acceptance rate of the rejuvenation step falls below this threshold, the
10-
#' number of particle filters is doubled. Defaults to 0.2.
11-
#' @param max_rejuvenation_steps Maximum number of rejuvenation steps. If the
12-
#' number of unique particles has not exceeded half the number of particles
13-
#' after this many steps, the rejuvenation is still stopped.
14-
#' @param metric Metric
15-
#' @param resampler resampler
16-
#' @param latent_rank_proposal latent rank proposal
17-
#' @param verbose Boolean
18-
#' @param trace Logical specifying whether to save static parameters at each
19-
#' timestep.
20-
#' @param trace_latent Logical specifying whether to sample and save one
21-
#' complete set of latent rankings for each particle and each timepoint.
3+
#' This function creates a list of options for the Sequential Monte Carlo (SMC²)
4+
#' algorithm used in Bayesian inference for the Mallows model. These options
5+
#' control the behavior of the particle filtering and resampling procedures.
226
#'
23-
#' @return A list
7+
#' @param n_particles Positive integer specifying the number of particles to use
8+
#' in the SMC algorithm. Default is 1000.
9+
#' @param n_particle_filters Positive integer specifying the initial number of
10+
#' particle filters for each particle. Default is 50.
11+
#' @param max_particle_filters Positive integer specifying the maximum number
12+
#' of particle filters allowed. Default is 10000.
13+
#' @param resampling_threshold Positive numeric value specifying the effective
14+
#' sample size threshold for triggering resampling. Default is n_particles/2.
15+
#' @param doubling_threshold Numeric value between 0 and 1 specifying the
16+
#' threshold for particle filter doubling. If the acceptance rate of the
17+
#' rejuvenation step falls below this threshold, the number of particle
18+
#' filters is doubled. Default is 0.2.
19+
#' @param max_rejuvenation_steps Positive integer specifying the maximum number
20+
#' of rejuvenation steps. If the number of unique particles has not exceeded
21+
#' half the number of particles after this many steps, the rejuvenation is
22+
#' stopped. Default is 20.
23+
#' @param metric Character string specifying the distance metric to use.
24+
#' Options include "footrule", "kendall", "spearman", "cayley", "hamming",
25+
#' and "ulam". Default is "footrule".
26+
#' @param resampler Character string specifying the resampling method.
27+
#' Options include "multinomial", "residual", "stratified", and "systematic".
28+
#' Default is "multinomial".
29+
#' @param latent_rank_proposal Character string specifying the proposal
30+
#' distribution for latent rankings. Default is "uniform".
31+
#' @param verbose Logical value indicating whether to print progress messages
32+
#' during computation. Default is FALSE.
33+
#' @param trace Logical value specifying whether to save static parameters at
34+
#' each timestep. Default is FALSE.
35+
#' @param trace_latent Logical value specifying whether to sample and save one
36+
#' complete set of latent rankings for each particle and each timepoint.
37+
#' Default is FALSE.
38+
#'
39+
#' @return A list containing all the SMC options with the specified values.
40+
#'
41+
#' @examples
42+
#' # Default SMC options
43+
#' opts <- set_smc_options()
44+
#'
45+
#' # Custom SMC options with fewer particles and Kendall distance
46+
#' opts <- set_smc_options(
47+
#' n_particles = 500,
48+
#' n_particle_filters = 25,
49+
#' metric = "kendall",
50+
#' verbose = TRUE
51+
#' )
52+
#'
53+
#' # Options for tracing parameters
54+
#' opts <- set_smc_options(
55+
#' n_particles = 100,
56+
#' trace = TRUE,
57+
#' trace_latent = TRUE
58+
#' )
59+
#'
2460
#' @export
2561
#'
2662
set_smc_options <- function(

0 commit comments

Comments
 (0)