Skip to content

Commit

Permalink
Added warning if stopping condition is not met.
Browse files Browse the repository at this point in the history
  • Loading branch information
pcarbo committed Mar 25, 2024
1 parent fd4acb4 commit c71461e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Encoding: UTF-8
Type: Package
Package: fastTopics
Version: 0.6-169
Date: 2024-03-18
Version: 0.6-171
Date: 2024-03-25
Title: Fast Algorithms for Fitting Topic Models and Non-Negative
Matrix Factorizations to Count Data
Authors@R: c(person("Peter","Carbonetto",role=c("aut","cre"),
Expand Down
19 changes: 14 additions & 5 deletions R/fit_poisson_nmf.R
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ fit_poisson_nmf <- function (X, k, fit0, numiter = 100,
cat(sprintf("Running at most %d %s updates, %s extrapolation ",
numiter,method.text,
ifelse(control$extrapolate,"with","without")))
cat("(fastTopics 0.6-169).\n")
cat("(fastTopics 0.6-171).\n")
}

# INITIALIZE ESTIMATES
Expand Down Expand Up @@ -495,6 +495,7 @@ fit_poisson_nmf_main_loop <- function (X, fit, numiter, update.factors,
"extrapolate","beta","betamax","timing")

# Iterate the updates of the factors and loadings.
converged <- FALSE
for (i in 1:numiter) {
fit0 <- fit
t1 <- proc.time()
Expand Down Expand Up @@ -556,20 +557,28 @@ fit_poisson_nmf_main_loop <- function (X, fit, numiter, update.factors,
if (control$min.res >= 0 & res < control$min.res) {
if (verbose == "progressbar")
pb$terminate()
cat("Stopping condition is satisfied: ")
cat(sprintf("maximum KKT residual < %0.2e\n",control$min.res))
cat(sprintf("Stopping condition is met at iteration %d: ",i))
cat(sprintf("max. KKT residual < %0.2e\n",control$min.res))
converged <- TRUE
break
} else if (control$min.delta.loglik >= 0 &
loglik.diff < control$min.delta.loglik) {
if (verbose == "progressbar")
pb$terminate()
cat("Stopping condition is satisfied: ")
cat(sprintf("change in Poisson NMF loglik < %0.2e\n",
cat(sprintf("Stopping condition is met at iteration %d: ",i))
cat(sprintf("change in NMF loglik < %0.2e\n",
control$min.delta.loglik))
converged <- TRUE
break
}
}

# Print a warning if one or more of the stopping criteria were not
# satisfied.
if (!converged & with(control,min.res >= 0 | min.delta.loglik >= 0))
warning(sprintf(paste("One or both stopping conditions were not met",
"within %d iterations"),numiter))

# Output the updated "fit".
progress <- progress[1:i,]
fit$progress <- progress
Expand Down

0 comments on commit c71461e

Please sign in to comment.