Skip to content

Commit

Permalink
Minor edits for compliance with R 4.0.0. Improved handling of suggest…
Browse files Browse the repository at this point in the history
…ed packages Rmpfr & gmp in G_expected, G_variance, and G_priorDensity. Minor speed-up to Procrustes when dilate=TRUE. summary.Results_IMIFA gains the printing-related argument "MAP". Minor fixes for negative discount (an experimental feature). Minor efficiency gain to slice sampler for IM(I)FA methods. Edited printed details when `plot.meth="zlabels"` with unsupplied `zlabels`.
  • Loading branch information
Keefe-Murphy committed May 12, 2020
1 parent 1959489 commit b4ad869
Show file tree
Hide file tree
Showing 14 changed files with 157 additions and 109 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Package: IMIFA
Type: Package
Date: 2020-03-30
Date: 2020-05-12
Title: Infinite Mixtures of Infinite Factor Analysers and Related Models
Version: 2.1.2
Version: 2.1.3
Authors@R: c(person("Keefe", "Murphy", email = "[email protected]", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-7709-3159")),
person("Cinzia", "Viroli", email = "[email protected]", role = "ctb"),
person("Isobel Claire", "Gormley", email = "[email protected]", role = "ctb"))
Description: Provides flexible Bayesian estimation of Infinite Mixtures of Infinite Factor Analysers and related models, for nonparametrically clustering high-dimensional data, introduced by Murphy et al. (2019) <doi:10.1214/19-BA1179>. The IMIFA model conducts Bayesian nonparametric model-based clustering with factor analytic covariance structures without recourse to model selection criteria to choose the number of clusters or cluster-specific latent factors, mostly via efficient Gibbs updates. Model-specific diagnostic tools are also provided, as well as many options for plotting results, conducting posterior inference on parameters of interest, posterior predictive checking, and quantifying uncertainty.
Depends: R (>= 3.3.0)
Depends: R (>= 4.0.0)
License: GPL (>= 2)
Encoding: UTF-8
URL: https://cran.r-project.org/package=IMIFA
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ S3method(plot,Results_IMIFA)
S3method(print,IMIFA)
S3method(print,Results_IMIFA)
S3method(print,summary_IMIFA)
S3method(print,summary_ResultsIMIFA)
S3method(scores_MAP,Results_IMIFA)
S3method(show_IMIFA_digit,Results_IMIFA)
S3method(sim_IMIFA_model,Results_IMIFA)
Expand Down
2 changes: 1 addition & 1 deletion R/Diagnostics.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#' Please be warned that this feature requires loading the \code{\link[mcclust]{mcclust}} package. This is liable to take considerable time to compute, and may not even be possible if the number of observations &/or number of stored iterations is large and the resulting matrix isn't sufficiently sparse. When \code{z.avgsim=TRUE}, both the summarised clustering and the similarity matrix are stored: the latter can be visualised as part of a call to \code{\link{plot.Results_IMIFA}}.
#' @param zlabels For any method that performs clustering, the true labels can be supplied if they are known in order to compute clustering performance metrics. This also has the effect of ordering the MAP labels (and thus the ordering of cluster-specific parameters) to most closely correspond to the true labels if supplied.
#' @param nonempty For "\code{MFA}" and "\code{MIFA}" models ONLY: a logical indicating whether only iterations with non-empty components should be retained. Defaults to \code{TRUE}, but may lead to empty chains - conversely, \code{FALSE} may lead to empty components and related errors.
#' @param x,object,... Arguments required for the \code{print.Results_IMIFA} and \code{summary.Results_IMIFA} functions: \code{x} and \code{object} are objects of class \code{"Results_IMIFA"} resulting from a call to \code{\link{get_IMIFA_results}}, while \code{...} gathers additional arguments to those functions.
#' @param x,object,MAP,... Arguments required for the \code{print.Results_IMIFA} and \code{summary.Results_IMIFA} functions: \code{x} and \code{object} are objects of class \code{"Results_IMIFA"} resulting from a call to \code{\link{get_IMIFA_results}}. \code{MAP} is a logical which governs whether a table of the MAP classification is printed, while \code{...} gathers additional arguments to those functions.
#'
#' Users can also pass the \code{type} argument to the \code{\link{norm}} function when \code{isTRUE(error.metrics)} and the posterior predictive reconstruction error (PPRE) is calculated. By default the Frobenius norm (\code{type="F"}) is employed.
#'
Expand Down
90 changes: 57 additions & 33 deletions R/FullConditionals.R

Large diffs are not rendered by default.

21 changes: 11 additions & 10 deletions R/Gibbs_IMFA.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
d.unif <- d.shape1 == 1 && d.shape2 == 1
.sim_disc_mh <- if(!learn.alpha && pi.alpha == 0) .sim_d_slab else .sim_d_spike
} else d.rates <- 1L
Dneg <- !learn.d && discount < 0
MH.step <- any(discount > 0, learn.d) && learn.alpha
if(MH.step) {
a.rates <- vector("integer", total)
Expand Down Expand Up @@ -131,6 +132,7 @@
pi.prop <- .sim_pi_inf(Vs, len=G)
index <- order(pi.prop, decreasing=TRUE)
prev.prod <- pi.prop[G] * (1/Vs[G] - 1)
GI <- which(Gs[index] == G)
pi.prop <- pi.prop[index]
Vs <- Vs[index]
mu[,Gs] <- mu[,index, drop=FALSE]
Expand Down Expand Up @@ -179,13 +181,13 @@
min.u <- min(u.slice)
G.old <- G
if(ind.slice) {
G.new <- sum(min.u < ksi)
G.new <- sum(min.u < ksi)
G.trunc <- G.new < G.old
while(G < G.new && (Vs[G] != 1 || pi.prop[G] != 0)) {
while(G < G.new && (Vs[GI] != 1 || pi.prop[GI] != 0)) {
newVs <- .sim_vs_inf(alpha=pi.alpha, discount=discount, len=1L, lseq=G + 1L)
Vs <- c(Vs, newVs)
pi.prop <- c(pi.prop, newVs * prev.prod)
G <- G + 1L
GI <- G <- G + 1L
prev.prod <- pi.prop[G] * (1/Vs[G] - 1)
}
G <- ifelse(G.trunc, G.new, G)
Expand All @@ -198,15 +200,15 @@
cum.pi <- sum(pi.prop)
u.max <- 1 - min.u
G.trunc <- cum.pi > u.max
while(cum.pi <= u.max && trunc.G > G && (pi.prop[G] != 0 || Vs[G] != 1)) {
while(cum.pi <= u.max && trunc.G > G && (pi.prop[GI] != 0 || Vs[GI] != 1)) {
newVs <- .sim_vs_inf(alpha=pi.alpha, discount=discount, len=1L, lseq=G + 1L)
Vs <- c(Vs, newVs)
newPis <- newVs * prev.prod
pi.prop <- c(pi.prop, newPis)
cum.pi <- cum.pi + newPis
ksi <- pi.prop
log.ksi <- c(log.ksi, log(newPis))
G <- G + 1L
GI <- G <- G + 1L
prev.prod <- pi.prop[G] * (1/Vs[G] - 1)
}
G <- ifelse(G.trunc, which.max(cumsum(pi.prop) > u.max), G)
Expand Down Expand Up @@ -249,15 +251,14 @@

# Alpha
if(learn.alpha) {
non.zero.d <- discount != 0
if(discount < 0) {
pi.alpha <- if(discount < 0) G * abs.disc else pi.alpha
} else if(isTRUE(non.zero.d)) {
if((non0d <- discount != 0) && Dneg) {
pi.alpha <- G * abs.disc
} else if(isTRUE(non0d)) {
MH.alpha <- .sim_alpha_m(alpha=pi.alpha, discount=discount, alpha.shape=alpha.shape, alpha.rate=alpha.rate, N=N, G=G.non, zeta=zeta)
pi.alpha <- MH.alpha$alpha
a.rate <- MH.alpha$rate
if(isTRUE(zeta.tune)) {
d.count <- d.count + non.zero.d
d.count <- d.count + non0d
if(iter >= startz &&
iter < stopz) {
zeta <- .tune_zeta(zeta=zeta, time=d.count, l.rate=MH.alpha$l.prob, heat=heat, target=target, lambda=lambda)
Expand Down
21 changes: 11 additions & 10 deletions R/Gibbs_IMIFA.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
d.unif <- d.shape1 == 1 && d.shape2 == 1
.sim_disc_mh <- if(!learn.alpha && pi.alpha == 0) .sim_d_slab else .sim_d_spike
} else d.rates <- 1L
Dneg <- !learn.d && discount < 0
MH.step <- any(discount > 0, learn.d) && learn.alpha
if(MH.step) {
a.rates <- vector("integer", total)
Expand Down Expand Up @@ -145,6 +146,7 @@
pi.prop <- .sim_pi_inf(Vs, len=G)
index <- order(pi.prop, decreasing=TRUE)
prev.prod <- pi.prop[G] * (1/Vs[G] - 1)
GI <- which(Gs[index] == G)
pi.prop <- pi.prop[index]
Vs <- Vs[index]
mu[,Gs] <- mu[,index, drop=FALSE]
Expand Down Expand Up @@ -237,13 +239,13 @@
min.u <- min(u.slice)
G.old <- G
if(ind.slice) {
G.new <- sum(min.u < ksi)
G.new <- sum(min.u < ksi)
G.trunc <- G.new < G.old
while(G < G.new && (Vs[G] != 1 || pi.prop[G] != 0)) {
while(G < G.new && (Vs[GI] != 1 || pi.prop[GI] != 0)) {
newVs <- .sim_vs_inf(alpha=pi.alpha, discount=discount, len=1L, lseq=G + 1L)
Vs <- c(Vs, newVs)
pi.prop <- c(pi.prop, newVs * prev.prod)
G <- G + 1L
GI <- G <- G + 1L
eta.tmp <- c(eta.tmp, list(.empty_mat(nc=Qs[G])))
prev.prod <- pi.prop[G] * (1/Vs[G] - 1)
}
Expand All @@ -257,15 +259,15 @@
cum.pi <- sum(pi.prop)
u.max <- 1 - min.u
G.trunc <- cum.pi > u.max
while(cum.pi <= u.max && trunc.G > G && (pi.prop[G] != 0 || Vs[G] != 1)) {
while(cum.pi <= u.max && trunc.G > G && (pi.prop[GI] != 0 || Vs[GI] != 1)) {
newVs <- .sim_vs_inf(alpha=pi.alpha, discount=discount, len=1L, lseq=G + 1L)
Vs <- c(Vs, newVs)
newPis <- newVs * prev.prod
pi.prop <- c(pi.prop, newPis)
cum.pi <- cum.pi + newPis
ksi <- pi.prop
log.ksi <- c(log.ksi, log(newPis))
G <- G + 1L
GI <- G <- G + 1L
eta.tmp <- c(eta.tmp, list(.empty_mat(nc=Qs[G])))
prev.prod <- pi.prop[G] * (1/Vs[G] - 1)
}
Expand Down Expand Up @@ -371,15 +373,14 @@

# Alpha
if(learn.alpha) {
non.zero.d <- discount != 0
if(discount < 0) {
pi.alpha <- if(discount < 0) G * abs.disc else pi.alpha
} else if(isTRUE(non.zero.d)) {
if((non0d <- discount != 0) && Dneg) {
pi.alpha <- G * abs.disc
} else if(isTRUE(non0d)) {
MH.alpha <- .sim_alpha_m(alpha=pi.alpha, discount=discount, alpha.shape=alpha.shape, alpha.rate=alpha.rate, N=N, G=G.non, zeta=zeta)
pi.alpha <- MH.alpha$alpha
a.rate <- MH.alpha$rate
if(isTRUE(zeta.tune)) {
d.count <- d.count + non.zero.d
d.count <- d.count + non0d
if(iter >= startz &&
iter < stopz) {
zeta <- .tune_zeta(zeta=zeta, time=d.count, l.rate=MH.alpha$l.prob, heat=heat, target=target, lambda=lambda)
Expand Down
4 changes: 2 additions & 2 deletions R/IMIFA.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#' \itemize{
#' \item{Type: }{Package}
#' \item{Package: }{IMIFA}
#' \item{Version: }{2.1.2}
#' \item{Date: }{2020-03-30 (this version), 2017-02-02 (original release)}
#' \item{Version: }{2.1.3}
#' \item{Date: }{2020-05-12 (this version), 2017-02-02 (original release)}
#' \item{Licence: }{GPL (>=2)}
#' }
#'
Expand Down
Loading

0 comments on commit b4ad869

Please sign in to comment.