Skip to content

Commit

Permalink
RANDOM: memory efficiency
Browse files Browse the repository at this point in the history
  • Loading branch information
gregreich committed Aug 26, 2021
1 parent 4ff6c45 commit 85f3e62
Showing 1 changed file with 34 additions and 9 deletions.
43 changes: 34 additions & 9 deletions R/RECOM_RANDOM.R
Expand Up @@ -70,15 +70,40 @@ BIN_RANDOM <- function(data=NULL, parameter=NULL) {

if(ncol(newdata) != length(model$labels)) stop("number of items in newdata does not match model.")

ratings <- new("realRatingMatrix",
data = dropNA(matrix(runif(n = nrow(newdata)*ncol(newdata)),
nrow = nrow(newdata))),
normalize = NULL
)
rownames(ratings) <- rownames(newdata)
colnames(ratings) <- model$labels

returnRatings(ratings, newdata, type, n)
for(i in 1:nrow(newdata)) {
ratings_user <- new("realRatingMatrix",
data = dropNA(matrix(runif(n = ncol(newdata)), nrow = 1)),
normalize = NULL
)

rownames(ratings_user) <- rownames(newdata[i,])
colnames(ratings_user) <- model$labels

ratings_user <- as(returnRatings(ratings_user, newdata[i,], type, n),"dgCMatrix")
if (i==1){
ratings <- ratings_user
}else{
ratings <- rbind(ratings, ratings_user)
}
}

ratings <- new("realRatingMatrix", data = ratings)

if(type=="topNList")
ratings <- getTopNLists(ratings, n = n)

ratings

# # original code
# ratings <- new("realRatingMatrix",
# data = dropNA(matrix(runif(n = nrow(newdata)*ncol(newdata)),
# nrow = nrow(newdata))),
# normalize = NULL
# )
# rownames(ratings) <- rownames(newdata)
# colnames(ratings) <- model$labels
#
# returnRatings(ratings, newdata, type, n)
}

## this recommender has no model
Expand Down

0 comments on commit 85f3e62

Please sign in to comment.