Skip to content

Commit

Permalink
preemtive check and error message for start_with_ALS=TRUE fixes #41
Browse files Browse the repository at this point in the history
  • Loading branch information
david-cortes committed Mar 17, 2023
1 parent 1d2e3b7 commit 3f6ec09
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion R/fit.R
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,7 @@ validate.inputs <- function(model, implicit=FALSE,
user_mapping <- character()
item_mapping <- character()
if (reindex) {
temp <- reindex.data(X, U, I, U_bin, I_bin)
temp <- reindex.data(X, U, I, U_bin, I_bin, (model %in% c("ContentBased", "OMF_explicit")) && start_with_ALS)
X <- temp$X
U <- temp$U
I <- temp$I
Expand Down
13 changes: 11 additions & 2 deletions R/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ cast.df.to.matrix <- function(df) {
return(df)
}

reindex.data <- function(X, U=NULL, I=NULL, U_bin=NULL, I_bin=NULL) {
reindex.data <- function(X, U=NULL, I=NULL, U_bin=NULL, I_bin=NULL, disallow_padding_U_I=FALSE) {
out <- list(
user_mapping = character(),
item_mapping = character(),
Expand Down Expand Up @@ -136,7 +136,11 @@ reindex.data <- function(X, U=NULL, I=NULL, U_bin=NULL, I_bin=NULL) {
all_U <- unique(union(users_X, users_U))
if ((!is.null(U) || !is.null(U_bin)) && !NROW(in_X_and_U))
stop("'X' and 'U'/'U_bin' have no IDs in common.")

if (disallow_padding_U_I) {
if (NROW(in_X_not_in_U)) {
stop("'U' must have all rows from 'X' when passing 'start_with_ALS=TRUE'.")
}
}

### Entries in I
items_X <- unique(X[[2L]])
Expand All @@ -152,6 +156,11 @@ reindex.data <- function(X, U=NULL, I=NULL, U_bin=NULL, I_bin=NULL) {
all_I <- unique(union(items_X, items_I))
if ((!is.null(I) || !is.null(I_bin)) && !NROW(in_X_and_I))
stop("'X' and 'I'/'I_bin' have no IDs in common.")
if (disallow_padding_U_I) {
if (NROW(in_X_not_in_I)) {
stop("'I' must have all columns from 'X' when passing 'start_with_ALS=TRUE'.")
}
}


### Now map and fill
Expand Down

0 comments on commit 3f6ec09

Please sign in to comment.