Skip to content

Commit

Permalink
fixed bug in projection method
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Weine committed Aug 1, 2024
1 parent 5c42575 commit 7222d45
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 19 deletions.
20 changes: 2 additions & 18 deletions R/fit.R
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,10 @@ fit_glmpca_pois <- function(
)

# now, I need to reconstruct FF, and hopefully compute the log-likelihood
FF[, train_idx] <- FF_train
FF[, train_idx] <- res$fit$FF
FF[, test_idx] <- FF_to_update
res$fit$FF <- FF

print(glue::glue("train loglik = {res$loglik}"))

if (inherits(Y,"sparseMatrix")) {
test_loglik_const <- sum(mapSparse(Y_test,lfactorial))
loglik_func <- lik_glmpca_pois_log_sp
Expand All @@ -294,21 +292,7 @@ fit_glmpca_pois <- function(
}

test_loglik <- loglik_func(Y_test,res$fit$LL,FF_to_update,test_loglik_const)
print(glue::glue("test loglik = {test_loglik}"))

print(glue::glue("Expected total loglik = {res$loglik + test_loglik}"))

if (inherits(Y,"sparseMatrix")) {
loglik_const <- sum(mapSparse(Y,lfactorial))
loglik_func <- lik_glmpca_pois_log_sp
} else {
loglik_const <- sum(lfactorial(Y))
loglik_func <- lik_glmpca_pois_log
}

res$loglik <- loglik_func(Y,res$fit$LL,res$fit$FF,loglik_const)

print(glue::glue("Calculated loglik = {res$loglik}"))
res$loglik <- res$loglik + test_loglik

}

Expand Down
2 changes: 1 addition & 1 deletion inst/scratch/test_projection_method.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ set.seed(1)
fit2 <- fit_glmpca_pois(
Y = pbmc_facs$counts,
K = 2,
control = list(training_frac = 0.99, maxiter = 10)
control = list(training_frac = 0.99, maxiter = 5)
)
#
# df1 <- data.frame(
Expand Down

0 comments on commit 7222d45

Please sign in to comment.