diff --git a/NAMESPACE b/NAMESPACE index 4cce859..244ac7a 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -20,6 +20,8 @@ exportClasses(StatNMoE) exportClasses(StatSNMoE) exportClasses(StatStMoE) exportClasses(StatTMoE) +import(MASS) import(methods) +import(pracma) importFrom(Rcpp,sourceCpp) useDynLib(meteorits, .registration = TRUE) diff --git a/R/ParamSNMoE.R b/R/ParamSNMoE.R index c619ebd..f7258d4 100755 --- a/R/ParamSNMoE.R +++ b/R/ParamSNMoE.R @@ -25,7 +25,7 @@ #' \eqn{(1, K)}). #' @field lambda The skewness parameters for each experts (matrix of size #' \eqn{(1, K)}). -#' @field delta delta is equal \eqn{\delta = +#' @field delta delta is equal to \eqn{\delta = #' \frac{\lambda}{\sqrt{1+\lambda^2}}}{\delta = \lambda / #' (1+\lambda^2)^(1/2)}. #' @field df The degree of freedom of the SNMoE model representing the @@ -123,6 +123,7 @@ ParamSNMoE <- setRefClass( Z <- matrix(0, nrow = n, ncol = K) Z[klas %*% ones(1, K) == ones(n, 1) %*% seq(K)] <- 1 tau <- Z + res <- IRLS(phiAlpha$XBeta, tau, ones(nrow(tau), 1), alpha) alpha <<- res$W @@ -147,6 +148,7 @@ ParamSNMoE <- setRefClass( \\code{statSNMoE} of class \\link{StatSNMoE} (which contains the E-step)." res_irls <- IRLS(phiAlpha$XBeta, statSNMoE$tik, ones(nrow(statSNMoE$tik), 1), alpha, verbose_IRLS) + statSNMoE$piik <- res_irls$piik reg_irls <- res_irls$reg_irls @@ -156,6 +158,7 @@ ParamSNMoE <- setRefClass( # Update the regression coefficients tauik_Xbeta <- (statSNMoE$tik[, k] %*% ones(1, p + 1)) * phiBeta$XBeta + beta[, k] <<- solve((t(tauik_Xbeta) %*% phiBeta$XBeta)) %*% (t(tauik_Xbeta) %*% (Y - delta[k] * statSNMoE$E1ik[, k])) # Update the variances sigma2k diff --git a/R/ParamStMoE.R b/R/ParamStMoE.R index 391f71e..f4718af 100755 --- a/R/ParamStMoE.R +++ b/R/ParamStMoE.R @@ -25,7 +25,7 @@ #' \eqn{(1, K)}). #' @field lambda The skewness parameters for each experts (matrix of size #' \eqn{(1, K)}). -#' @field delta delta is equal \eqn{\delta = +#' @field delta delta is equal to \eqn{\delta = #' \frac{\lambda}{\sqrt{1+\lambda^2}}}{\delta = \lambda / #' (1+\lambda^2)^(1/2)}. #' @field nu The degree of freedom for the Student distribution for each diff --git a/R/StatSNMoE.R b/R/StatSNMoE.R index 6a0e98d..220ade6 100755 --- a/R/StatSNMoE.R +++ b/R/StatSNMoE.R @@ -166,9 +166,13 @@ StatSNMoE <- setRefClass( # E1ik = E[Ui|yi,xi,zik=1] E1ik[, k] <<- mu_uk + sigma_uk * dnorm(paramSNMoE$lambda[k] * dik, 0, 1) / pnorm(paramSNMoE$lambda[k] * dik, 0, 1) + E1ik[is.nan(E1ik[, k]), k] <<- mu_uk[is.nan(E1ik[, k])] - sigma_uk * paramSNMoE$lambda[k] * dik[is.nan(E1ik[, k])] + E1ik[is.infinite(E1ik[, k]), k] <<- mu_uk[is.infinite(E1ik[, k])] - sigma_uk * paramSNMoE$lambda[k] * dik[is.infinite(E1ik[, k])] # E2ik = E[Ui^2|y,zik=1] E2ik[, k] <<- mu_uk ^ 2 + sigma_uk ^ 2 + sigma_uk * mu_uk * dnorm(paramSNMoE$lambda[k] * dik, 0, 1) / pnorm(paramSNMoE$lambda[k] * dik, 0, 1) + E2ik[is.nan(E2ik[, k]), k] <<- mu_uk[is.nan(E2ik[, k])] ^ 2 + sigma_uk ^ 2 - sigma_uk * mu_uk[is.nan(E2ik[, k])] * paramSNMoE$lambda[k] * dik[is.nan(E2ik[, k])] + E2ik[is.infinite(E2ik[, k]), k] <<- mu_uk[is.infinite(E2ik[, k])] ^ 2 + sigma_uk ^ 2 - sigma_uk * mu_uk[is.infinite(E2ik[, k])] * paramSNMoE$lambda[k] * dik[is.infinite(E2ik[, k])] # weighted skew normal linear expert likelihood piik_fik[, k] <- piik[, k] * (2 / sigmak) * dnorm(dik, 0, 1) * pnorm(paramSNMoE$lambda[k] * dik) @@ -179,7 +183,9 @@ StatSNMoE <- setRefClass( log_sum_piik_fik <<- matrix(log(rowSums(piik_fik))) # E[Zik|y,x] and E[U^2|y,zik=1] - tik <<- piik_fik / (rowSums(piik_fik) %*% ones(1, paramSNMoE$K)) + # tik <<- piik_fik / (rowSums(piik_fik) %*% ones(1, paramSNMoE$K)) + log_Tauik <- log_piik_fik - logsumexp(log_piik_fik, 1) %*% ones(1, paramSNMoE$K) + tik <<- exp(log_Tauik) } ) ) diff --git a/R/logsumexp.R b/R/logsumexp.R index 38dec40..cdabf5b 100755 --- a/R/logsumexp.R +++ b/R/logsumexp.R @@ -7,7 +7,7 @@ logsumexp <- function(A, margin) { A <- xstar + log(apply(exp(M), 1, sum)) } else{ xstar <- apply(A, 2, max) - M <- M - matrix(1, nrow = row(M), ncol = 1) %*% xstar + M <- M - matrix(1, nrow = nrow(M), ncol = 1) %*% xstar A <- xstar + log(apply(exp(M), 2, sum)) } return(A) diff --git a/R/meteorits-package.R b/R/meteorits-package.R index b98126b..39c88ec 100755 --- a/R/meteorits-package.R +++ b/R/meteorits-package.R @@ -10,17 +10,17 @@ #' `meteorits` contains the following Mixture-of-Experts models: #' #' \itemize{ -#' \item NMoE provides a flexible framework for heterogenous data with -#' Normal expert regressors network; -#' \item SNMoE provides a flexible modeling framework for heterogenous -#' data with possibly skewed distributions to generalize the standard Normal -#' mixture of expert model; -#' \item TMoE provides a flexible and robust modeling framework for -#' heterogenous data with possibly heavy-tailed distributions and corrupted by -#' atypical observations; -#' \item StMoE provides a flexible and robust modeling framework for -#' heterogenous data with possibly skewed, heavy-tailed distributions and -#' corrupted by atypical observations. +#' \item NMoE (Normal Mixtures-of-Experts) provides a flexible framework for +#' heterogenous data with Normal expert regressors network; +#' \item SNMoE (Skew-Normal Mixtures-of-Experts) provides a flexible +#' modeling framework for heterogenous data with possibly skewed +#' distributions to generalize the standard Normal mixture of expert model; +#' \item tMoE (t Mixtures-of-Experts) provides a flexible and robust +#' modeling framework for heterogenous data with possibly heavy-tailed +#' distributions and corrupted by atypical observations; +#' \item StMoE (Skew t Mixtures-of-Experts) provides a flexible and robust +#' modeling framework for heterogenous data with possibly skewed, +#' heavy-tailed distributions and corrupted by atypical observations. #' } #' #' For the advantages/differences of each of them, the user is referred to our @@ -46,6 +46,8 @@ #' Chamroukhi, F., A. Same, G. Govaert, and P. Aknin. 2009. \emph{Time Series Modeling by a Regression Approach Based on a Latent Process.} Neural Networks 22 (5-6): 593--602. \url{https://chamroukhi.com/papers/Chamroukhi_Neural_Networks_2009.pdf}. #' #' @import methods +#' @import pracma +#' @import MASS ## usethis namespace: start #' @useDynLib meteorits, .registration = TRUE ## usethis namespace: end diff --git a/inst/CITATION b/inst/CITATION index 2b1abb5..2b6a4bd 100644 --- a/inst/CITATION +++ b/inst/CITATION @@ -1,4 +1,7 @@ -citHeader("To cite meteorits in publications use:") +citHeader("To cite the package meteorits in a publication please use the +following reference. To cite the corresponding paper for a specific package +from meteorits (e.g NMoE, SNMoE, tMoE, StMoE, etc), please choose the +reference(s) from the list provided below.") note <- sprintf("R package version %s", meta$Version) @@ -7,69 +10,76 @@ citEntry( title = "meteorits: Mixtures-of-Experts Modeling for Complex and Non-Normal Distributions ('MEteorits')", author = personList(person(given="F.", family="Chamroukhi"), - person(given="M.", family="Bartcus"), - person(given="F.", family="Lecocq")), + person(given="F.", family="Lecocq"), + person(given="M.", family="Bartcus")), year = "2019", note = note, url = "https://github.com/fchamroukhi/MEteorits", - textVersion = paste0("Faicel Chamroukhi, Marius Bartcus and Florian Lecocq (2019). + textVersion = paste0("Faicel Chamroukhi, Florian Lecocq and Marius Bartcus (2019). meteorits: Mixtures-of-Experts Modeling for Complex and Non-Normal Distributions ('MEteorits'). ", note, ". https://github.com/fchamroukhi/MEteorits") ) citEntry( - entry = "Article", + entry = "Article", author = personList(person(given="B-T.", family="Huynh"), person(given="F.", family="Chamroukhi")), - journal = "Journal de la Societe Francaise de Statistique", - title = "Estimation and Feature Selection in Mixtures of Generalized Linear Experts Models.", + journal = "Journal de la Soci\\'{e}t\\'{e} Fran\\c{c}aise de Statistique", + title = "Estimation and Feature Selection in Mixtures of Generalized Linear Experts Models", year = "2019", - url = "https://chamroukhi.com/papers/Chamroukhi_Huynh_jsfds-published.pdf", - textVersion = "B-T. Huynh and F. Chamroukhi (2019). \u201cEstimation and Feature Selection in Mixtures of Generalized Linear Experts Models.\u201d Journal de la Societe Francaise de Statistique. ." ) citEntry( @@ -81,33 +91,33 @@ citEntry( volume = "79", pages = "20--36", url = "https://chamroukhi.com/papers/TMoE.pdf", - textVersion = "Chamroukhi F (2016). \u201cRobust mixture of experts modeling using the - t-distribution.\u201d Neural Networks - Elsevier, 79, pp. 20-36. + textVersion = "Chamroukhi F (2016). \u201cRobust mixture of experts modeling + using the t-distribution.\u201d Neural Networks - Elsevier, *79*, 20-36. ." ) citEntry( - entry = "InProceedings", - title = "Skew-Normal Mixture of Experts", + entry = "InProceedings", + title = "Skew-Normal Mixture of Experts", author = personList(person(given="F.", family="Chamroukhi")), - booktitle = "The International Joint Conference on Neural Networks (IJCNN)", - year = "2016", - url = "https://chamroukhi.com/papers/Chamroukhi-SNMoE-IJCNN2016.pdf", - textVersion = "Chamroukhi F (2016). \u201cSkew-Normal Mixture of Experts.\u201d In - The International Joint Conference on Neural Networks (IJCNN). - ." + booktitle = "The International Joint Conference on Neural Networks (IJCNN)", + year = "2016", + url = "https://chamroukhi.com/papers/Chamroukhi-SNMoE-IJCNN2016.pdf", + textVersion = "Chamroukhi F (2016). \u201cSkew-Normal Mixture of + Experts.\u201d In The International Joint Conference on Neural Networks (IJCNN). + ." ) citEntry( entry = "PhdThesis", title = "Statistical learning of latent data models for complex data analysis", author = person(given="F.", family="Chamroukhi"), - school = "Universit\u00e9 de Toulon", + school = "Universit\\'{e} de Toulon", year = "2015", type = "Habilitation Thesis (HDR)", url = "https://chamroukhi.com/Dossier/FChamroukhi-Habilitation.pdf", - textVersion = "Chamroukhi F (2015). Statistical learning of latent data models for - complex data analysis. Habilitation Thesis (HDR), Universit\u00e9 de Toulon. + textVersion = "Chamroukhi F (2015). Statistical learning of latent data models + for complex data analysis. PhD thesis, Universit\u00e9 de Toulon. ." ) @@ -115,26 +125,28 @@ citEntry( entry = "PhdThesis", title = "Hidden process regression for curve modeling, classification and tracking", author = person(given="F.", family="Chamroukhi"), - school = "Universit\'{e} de Technologie de Compi\`{e}gne", + school = "Universit\\'{e} de Technologie de Compi\\`{e}gne", year = "2010", type = "Ph.D. Thesis", url = "https://chamroukhi.com/papers/FChamroukhi-Thesis.pdf", - textVersion = "Chamroukhi F (2010). \u201cHidden process regression for curve - modeling, classification and tracking\u201d. Ph.D. Thesis, Universit\u00e9 de - Technologie de Compi\u00e8gne. - ." + textVersion = "Chamroukhi F (2010). Hidden process regression for curve + modeling, classification and tracking. PhD thesis, Universit\u00e9 de Technologie + de Compi\u00e8gne. ." ) citEntry( entry = "Article", - title = "Time series modeling by a regression approach based on a latent process.", + title = "Time series modeling by a regression approach based on a latent process", author = personList(person(given="F.", family="Chamroukhi"), - person(given="A.", family="Sam\u00e9"), + person(given="A.", family="Sam\\'{e}"), person(given="G.", family="Govaert"), person(given="P.", family="Aknin")), journal = "Neural Networks Elsevier Science Ltd.", year = "2009", - volume = "22(5-6)", + volume = "22", + number = "5-6", pages = "593--602", - textVersion = "F. Chamroukhi and A. Sam\u00e9 and G. Govaert and P. Aknin (2009). \u201cTime series modeling by a regression approach based on a latent process.\u201d Neural Networks Elsevier Science Ltd., vol. 22(5-6), pp. 593--602." + textVersion = "Chamroukhi F, Sam\u00e9 A, Govaert G, Aknin P (2009). \u201cTime + series modeling by a regression approach based on a latent process.\u201d + Neural Networks Elsevier Science Ltd., *22(5-6)*, 593-602." ) diff --git a/man/ParamSNMoE-class.Rd b/man/ParamSNMoE-class.Rd index 17290e3..5aad93f 100644 --- a/man/ParamSNMoE-class.Rd +++ b/man/ParamSNMoE-class.Rd @@ -44,7 +44,7 @@ default.} \item{\code{lambda}}{The skewness parameters for each experts (matrix of size \eqn{(1, K)}).} -\item{\code{delta}}{delta is equal \eqn{\delta = +\item{\code{delta}}{delta is equal to \eqn{\delta = \frac{\lambda}{\sqrt{1+\lambda^2}}}{\delta = \lambda / (1+\lambda^2)^(1/2)}.} diff --git a/man/ParamStMoE-class.Rd b/man/ParamStMoE-class.Rd index 7891647..ce8dfda 100644 --- a/man/ParamStMoE-class.Rd +++ b/man/ParamStMoE-class.Rd @@ -44,7 +44,7 @@ default.} \item{\code{lambda}}{The skewness parameters for each experts (matrix of size \eqn{(1, K)}).} -\item{\code{delta}}{delta is equal \eqn{\delta = +\item{\code{delta}}{delta is equal to \eqn{\delta = \frac{\lambda}{\sqrt{1+\lambda^2}}}{\delta = \lambda / (1+\lambda^2)^(1/2)}.} diff --git a/man/meteorits-package.Rd b/man/meteorits-package.Rd index 37c33b3..f98da41 100644 --- a/man/meteorits-package.Rd +++ b/man/meteorits-package.Rd @@ -16,17 +16,17 @@ sparse mixture-of-experts models for high-dimensional data. \code{meteorits} contains the following Mixture-of-Experts models: \itemize{ -\item NMoE provides a flexible framework for heterogenous data with -Normal expert regressors network; -\item SNMoE provides a flexible modeling framework for heterogenous -data with possibly skewed distributions to generalize the standard Normal -mixture of expert model; -\item TMoE provides a flexible and robust modeling framework for -heterogenous data with possibly heavy-tailed distributions and corrupted by -atypical observations; -\item StMoE provides a flexible and robust modeling framework for -heterogenous data with possibly skewed, heavy-tailed distributions and -corrupted by atypical observations. +\item NMoE (Normal Mixtures-of-Experts) provides a flexible framework for +heterogenous data with Normal expert regressors network; +\item SNMoE (Skew-Normal Mixtures-of-Experts) provides a flexible +modeling framework for heterogenous data with possibly skewed +distributions to generalize the standard Normal mixture of expert model; +\item tMoE (t Mixtures-of-Experts) provides a flexible and robust +modeling framework for heterogenous data with possibly heavy-tailed +distributions and corrupted by atypical observations; +\item StMoE (Skew t Mixtures-of-Experts) provides a flexible and robust +modeling framework for heterogenous data with possibly skewed, +heavy-tailed distributions and corrupted by atypical observations. } For the advantages/differences of each of them, the user is referred to our diff --git a/meteorits_0.1.0.pdf b/meteorits_0.1.0.pdf index 2bad963..89e1943 100644 Binary files a/meteorits_0.1.0.pdf and b/meteorits_0.1.0.pdf differ diff --git a/src/IRLS.cpp b/src/IRLS.cpp index 49b7e0c..f4717c9 100644 --- a/src/IRLS.cpp +++ b/src/IRLS.cpp @@ -250,7 +250,7 @@ List IRLS(arma::mat& X, arma::mat& Tau, arma::mat& Gamma, arma::mat& Winit, bool } } else { Rcout << "\n"; - Rcout << "IRLS : doesn't converged (increase the number of iterations > " + std::to_string(iter) + ")\n"; + Rcout << "IRLS : did not converge (increase the number of iterations > " + std::to_string(max_iter) + ")\n"; } double reg_irls = 0;