2525# '
2626# ' @param hyperparameters A list returned from [set_hyperparameters()].
2727# ' @param smc_options A list returned from [set_smc_options()]
28- # ' @param topological_sorts_directory Path to a directory where precomputed
29- # ' topological sorts can be found. Must contain subdirectories with names
30- # ' `user1`, `user2`, etc., exactly matching the `user` column of `data`. See
31- # ' [precompute_topological_sorts()]. Defaults to `NULL`, but has to be
32- # ' provided when data contain pairwise preferences.
33- # '
34- # ' @param num_topological_sorts Integer vector containing the number of
35- # ' topological sorts for each user.
36- # ' @param file_count Integer vector containing the number of files with
37- # ' topological sorts for each user.
28+ # ' @param topological_sorts A list returned from
29+ # ' [precompute_topological_sorts()]. Only used with preference data, and
30+ # ' defaults to `NULL`.
3831# '
3932# ' @return An object
4033# ' @export
@@ -43,9 +36,7 @@ compute_sequentially <- function(
4336 data ,
4437 hyperparameters = set_hyperparameters(),
4538 smc_options = set_smc_options(),
46- topological_sorts_directory = NULL ,
47- num_topological_sorts = NULL ,
48- file_count = NULL
39+ topological_sorts = NULL
4940 ){
5041 rank_columns <- grepl(" item[0-9]+" , colnames(data ))
5142 preference_columns <- grepl(" top\\ _item|bottom\\ _item" , colnames(data ))
@@ -60,34 +51,33 @@ compute_sequentially <- function(
6051 } else {
6152 attr(input_timeseries , " type" ) <- " complete rankings"
6253 }
54+ sort_matrices <- sort_counts <- list ()
6355 } else if (sum(preference_columns ) == 2 ) {
64- if (is.null(topological_sorts_directory )) {
65- stop(" topological_sorts_directory must be provided with preference data." )
66- }
67- if (is.null(num_topological_sorts )) {
68- stop(" num_topological_sorts must be provided with preference data." )
69- }
70- if (is.null(file_count )) {
71- stop(" file_count must be provided with preference data." )
56+ if (is.null(topological_sorts )) {
57+ stop(" topological_sorts must be provided with preference data." )
7258 }
7359 input_timeseries <- split(data , f = ~ timepoint ) | >
7460 lapply(split , f = ~ user ) | >
7561 lapply(function (x ) lapply(x , function (y ) as.matrix(y [preference_columns ])))
7662 attr(input_timeseries , " type" ) <- " pairwise preferences"
77- attr(input_timeseries , " topological_sorts_directory" ) <- topological_sorts_directory
78- names(num_topological_sorts ) <- names(file_count ) <- as.character(lapply(input_timeseries , names ))
79- attr(input_timeseries , " num_topological_sorts" ) <- num_topological_sorts
80- attr(input_timeseries , " file_count" ) <- file_count
63+
64+ sort_matrices <- lapply(topological_sorts , function (x ) {
65+ lapply(x , function (y ) y $ sort_matrix )
66+ })
67+
68+ sort_counts <- lapply(topological_sorts , function (x ) {
69+ lapply(x , function (y ) y $ sort_count )
70+ })
8171 } else {
8272 stop(" Something wrong with data" )
8373 }
8474
85- attr(input_timeseries , " updated_users" ) <- FALSE
8675 if (max(table(data $ user )) > 1 &&
8776 attr(input_timeseries , " type" ) != " pairwise preferences" ) {
8877 stop(" Updated users not supported." )
8978 }
9079
91- ret <- run_smc(input_timeseries , hyperparameters , smc_options )
80+ ret <- run_smc(input_timeseries , hyperparameters , smc_options ,
81+ sort_matrices , sort_counts )
9282}
9383
0 commit comments