Skip to content

Commit

Permalink
Replace 'cat()' by 'message()'
Browse files Browse the repository at this point in the history
emMixHMM.R, emMixHMMR.R, emMixRHLP.R: Replace 'cat()' by 'message()'. Thus messages can be suppressed if needed.
  • Loading branch information
Florian-Lecocq committed Aug 5, 2019
1 parent e50288d commit 423691e
Show file tree
Hide file tree
Showing 25 changed files with 173 additions and 85 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Description: Provides a variety of original and flexible user-friendly
segmentation of heterogeneous functional data (i.e time series, or more
generally longitudinal data, fitted by unsupervised algorithms, including
EM algorithms. Functional Latent Data Models for Clustering heterogeneous
curves ('FLaMingos') are originally introduced and written in Matlab by
curves ('FLaMingos') are originally introduced and written in 'Matlab' by
Faicel Chamroukhi
<https://github.com/fchamroukhi?utf8=?&tab=repositories&q=mix&type=public&language=matlab>.
The references are mainly the following ones.
Expand Down
10 changes: 5 additions & 5 deletions R/cemMixRHLP.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ cemMixRHLP <- function(X, Y, K, R, p = 3, q = 1, variance_type = c("heteroskedas
while (try_CEM < n_tries) {
try_CEM <- try_CEM + 1
if (n_tries > 1 && verbose) {
cat(paste0("EM try number: ", try_CEM, "\n\n"))
message("EM try number: ", try_CEM, "\n")
}

# Initialization
Expand Down Expand Up @@ -103,11 +103,11 @@ cemMixRHLP <- function(X, Y, K, R, p = 3, q = 1, variance_type = c("heteroskedas

iter <- iter + 1
if (verbose) {
cat(paste0("CEM - mixRHLP: Iteration: ", iter, " | Complete log-likelihood: " , stat$com_loglik, "\n"))
message("CEM - mixRHLP: Iteration: ", iter, " | Complete log-likelihood: " , stat$com_loglik)
}

if (prev_com_loglik - stat$com_loglik > 1e-5) {
warning(paste0("CEM complete log-likelihood is decreasing from ", prev_com_loglik, "to ", stat$com_loglik, " !"))
warning("CEM complete log-likelihood is decreasing from ", prev_com_loglik, "to ", stat$com_loglik, " !")
top <- top + 1
if (top > 20)
break
Expand All @@ -129,12 +129,12 @@ cemMixRHLP <- function(X, Y, K, R, p = 3, q = 1, variance_type = c("heteroskedas
best_com_loglik <- stat$com_loglik
}
if (n_tries > 1 && verbose) {
cat(paste0("Max value of the complete log-likelihood: ", stat$com_loglik, "\n\n"))
message("Max value of the complete log-likelihood: ", stat$com_loglik, "\n\n")
}
}

if (n_tries > 1 && verbose) {
cat(paste0("Best value of the complete log-likelihood: ", statSolution$com_loglik, "\n"))
message("Best value of the complete log-likelihood: ", statSolution$com_loglik, "\n")
}

statSolution$computeStats(paramSolution)
Expand Down
10 changes: 5 additions & 5 deletions R/emMixHMM.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ emMixHMM <- function(Y, K, R, variance_type = c("heteroskedastic", "homoskedasti
try_EM <- try_EM + 1

if (n_tries > 1 && verbose) {
cat(paste0("EM try number: ", try_EM, "\n\n"))
message("EM try number: ", try_EM, "\n")
}

# Initialization
Expand All @@ -93,11 +93,11 @@ emMixHMM <- function(Y, K, R, variance_type = c("heteroskedastic", "homoskedasti
iter <- iter + 1

if (verbose) {
cat(paste0("EM - mixHMMs: Iteration: ", iter, " | log-likelihood: " , stat$loglik, "\n"))
message("EM - mixHMMs: Iteration: ", iter, " | log-likelihood: " , stat$loglik)
}

if (prev_loglik - stat$loglik > 1e-4) {
warning(paste0("EM log-likelihood is decreasing from ", prev_loglik, "to ", stat$loglik, " !"))
warning("EM log-likelihood is decreasing from ", prev_loglik, "to ", stat$loglik, " !")
}

converged <- (abs((stat$loglik - prev_loglik) / prev_loglik) <= threshold)
Expand All @@ -118,13 +118,13 @@ emMixHMM <- function(Y, K, R, variance_type = c("heteroskedastic", "homoskedasti
}

if (n_tries > 1 && verbose) {
cat(paste0("Max value of the log-likelihood: ", stat$loglik, "\n\n"))
message("Max value of the log-likelihood: ", stat$loglik, "\n\n")
}

}

if (n_tries > 1 && verbose) {
cat(paste0("Best value of the log-likelihood: ", statSolution$loglik, "\n\n"))
message("Best value of the log-likelihood: ", statSolution$loglik, "\n")
}

# Finding the curve partition by using the MAP rule
Expand Down
10 changes: 5 additions & 5 deletions R/emMixHMMR.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ emMixHMMR <- function(X, Y, K, R, p = 3, variance_type = c("heteroskedastic", "h
while (try_EM < n_tries) {
try_EM <- try_EM + 1
if (n_tries > 1 && verbose) {
cat(paste0("EM try number: ", try_EM, "\n\n"))
message("EM try number: ", try_EM, "\n")
}

# Initialization
Expand All @@ -95,11 +95,11 @@ emMixHMMR <- function(X, Y, K, R, p = 3, variance_type = c("heteroskedastic", "h
iter <- iter + 1

if (verbose) {
cat(paste0("EM - mixHMMR: Iteration: ", iter, " || log-likelihood: " , stat$loglik, "\n"))
message("EM - mixHMMR: Iteration: ", iter, " || log-likelihood: " , stat$loglik)
}

if (prev_loglik - stat$loglik > 1e-4) {
warning(paste0("EM log-likelihood is decreasing from ", prev_loglik, "to ", stat$loglik, " !"))
warning("EM log-likelihood is decreasing from ", prev_loglik, "to ", stat$loglik, " !")
}

converged <- (abs((stat$loglik - prev_loglik) / prev_loglik) < threshold)
Expand All @@ -120,13 +120,13 @@ emMixHMMR <- function(X, Y, K, R, p = 3, variance_type = c("heteroskedastic", "h
}

if (n_tries > 1 && verbose) {
cat(paste0("Max value of the log-likelihood: ", stat$loglik, "\n\n"))
message("Max value of the log-likelihood: ", stat$loglik, "\n\n")
}

}

if (n_tries > 1 && verbose) {
cat(paste0("Best value of the log-likelihood: ", statSolution$loglik, "\n"))
message("Best value of the log-likelihood: ", statSolution$loglik, "\n")
}

# Finding the curve partition by using the MAP rule
Expand Down
10 changes: 5 additions & 5 deletions R/emMixRHLP.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ emMixRHLP <- function(X, Y, K, R, p = 3, q = 1, variance_type = c("heteroskedast
while (try_EM < n_tries) {
try_EM <- try_EM + 1
if (n_tries > 1 && verbose) {
cat(paste0("EM try number: ", try_EM, "\n\n"))
message("EM try number: ", try_EM, "\n")
}

# Initialization
Expand All @@ -94,11 +94,11 @@ emMixRHLP <- function(X, Y, K, R, p = 3, q = 1, variance_type = c("heteroskedast

iter <- iter + 1
if (verbose) {
cat(paste0("EM - mixRHLP: Iteration: ", iter, " | log-likelihood: " , stat$loglik, "\n"))
message("EM - mixRHLP: Iteration: ", iter, " | log-likelihood: " , stat$loglik)
}

if (prev_loglik - stat$loglik > 1e-5) {
warning(paste0("EM log-likelihood is decreasing from ", prev_loglik, "to ", stat$loglik, " !"))
warning("EM log-likelihood is decreasing from ", prev_loglik, "to ", stat$loglik, " !")
top <- top + 1
if (top > 20) {
break
Expand All @@ -122,15 +122,15 @@ emMixRHLP <- function(X, Y, K, R, p = 3, q = 1, variance_type = c("heteroskedast
}

if (n_tries > 1 && verbose) {
cat(paste0("Max value of the log-likelihood: ", stat$loglik, "\n\n"))
message("Max value of the log-likelihood: ", stat$loglik, "\n\n")
}
}

# Computation of c_ig the hard partition of the curves and the cluster labels klas
statSolution$MAP()

if (n_tries > 1 && verbose) {
cat(paste0("Best value of the log-likelihood: ", statSolution$loglik, "\n"))
message("Best value of the log-likelihood: ", statSolution$loglik, "\n")
}

statSolution$computeStats(paramSolution)
Expand Down
8 changes: 4 additions & 4 deletions R/flamingos-package.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#' FLaMingos: Functional Latent datA Models for clusterING heterogeneOus curveS
#'
#' @description `flamingos` is an open-source toolbox for the simultaneous clustering (or
#' classification) and segmentation of heterogeneous functional data (i.e
#' time-series ore more generally longitudinal data), with original and
#' flexible functional latent variable models, fitted by unsupervised
#' @description `flamingos` is an open-source toolbox for the simultaneous
#' clustering (or classification) and segmentation of heterogeneous functional
#' data (i.e time-series ore more generally longitudinal data), with original
#' and flexible functional latent variable models, fitted by unsupervised
#' algorithms, including EM algorithms.
#'
#' `flamingos` contains the following time series clustering and segmentation models:
Expand Down
4 changes: 2 additions & 2 deletions R/kmeans.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ kmeans = function(X, K, nbr_runs = 20, nbr_iter_max = 300, verbose = FALSE) {
while (nb_run < nbr_runs) {
nb_run = nb_run + 1
if (nbr_runs > 0 && verbose) {
cat(sprintf("Kmeans : run n?? %1i", nb_run), "\n")
message(sprintf("Kmeans : run # %1i", nb_run), "\n")
}

iter = 0
Expand Down Expand Up @@ -91,7 +91,7 @@ kmeans = function(X, K, nbr_runs = 20, nbr_iter_max = 300, verbose = FALSE) {
previous_err = current_err

if (verbose) {
cat(sprintf("Kmeans : Iteration %1.1i, Objective %2.2f", iter, current_err), "\n")
message(sprintf("Kmeans : Iteration %1.1i, Objective %2.2f", iter, current_err), "\n")
}
solution$stored_err = cbind(solution$stored_err, current_err)
}
Expand Down
6 changes: 3 additions & 3 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ library(flamingos)
<details>
<summary>mixRHLP</summary>

```{r, message = FALSE}
```{r, echo=TRUE}
data("toydataset")
x <- toydataset$x
Y <- t(toydataset[,2:ncol(toydataset)])
Expand Down Expand Up @@ -102,7 +102,7 @@ mixrhlp$plot()
<details>
<summary>mixHMM</summary>

```{r, message = FALSE}
```{r, echo=TRUE}
data("toydataset")
Y <- t(toydataset[,2:ncol(toydataset)])
Expand Down Expand Up @@ -130,7 +130,7 @@ mixhmm$plot()
<details>
<summary>mixHMMR</summary>

```{r, message = FALSE}
```{r, echo=TRUE}
data("toydataset")
x <- toydataset$x
Y <- t(toydataset[,2:ncol(toydataset)])
Expand Down
Loading

0 comments on commit 423691e

Please sign in to comment.