Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class function g to m #266

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
update
  • Loading branch information
TahminaMojumder committed Oct 27, 2023
commit c892815fd7f2f868e0652bf58f1d49db6adb674f
115 changes: 57 additions & 58 deletions BayesianTools/R/classSMCSamplerList.R
Original file line number Diff line number Diff line change
@@ -1,58 +1,57 @@
#' Convenience function to create an object of class SMCSamplerList from a list of mcmc samplers
#' @author Florian Hartig
#' @param ... a list of MCMC samplers
#' @return a list of class smcSamplerList with objects of smcSampler
#' @export
createSmcSamplerList <- function(...){
smcList <- list(...)
for (i in 1:length(smcList)){
if (! ("mcmcSampler" %in% class(smcList[[i]])) ) stop("list objects are not of class mcmcSampler")
}
class(smcList) = c("smcSamplerList", "bayesianOutput")
return(smcList)
}


#' @method summary smcSamplerList
#' @author Florian Hartig
#' @export
summary.smcSamplerList <- function(object, ...){
sample = getSample(object, parametersOnly = T, ...)
summary(sample)
}

#' @method print smcSamplerList
#' @author Florian Hartig
#' @export
print.smcSamplerList <- function(x, ...){
print("smcSamplerList - you can use the following methods to summarize, plot or reduce this class:")
print(methods(class ="smcSamplerList"))
}

#' @method plot smcSamplerList
#' @export
plot.smcSamplerList <- function(x, ...){
marginalPlot(x, ...)
}

#' @export
getSample.smcSamplerList <- function(sampler, parametersOnly = T, coda = F, start = 1, end = NULL, thin = 1,
numSamples = NULL, whichParameters = NULL, reportDiagnostics = FALSE, ...){

out = list()

for (i in 1:length(sampler)){

out[[i]] = getSample(sampler[[i]], parametersOnly = parametersOnly, whichParameters = whichParameters, start = start, end = end, thin = thin,
numSamples = numSamples, coda = F, reportDiagnostics = F)

}
out = combineChains(out, merge =F)

return(out)
}





#' Convenience function to create an object of class SMCSamplerList from a list of mcmc samplers
#' @author Florian Hartig
#' @param ... a list of MCMC samplers
#' @return a list of class smcSamplerList with objects of smcSampler
#' @export
createSmcSamplerList <- function(...){
smcList <- list(...)
for (i in 1:length(smcList)){
if (! ("mcmcSampler" %in% class(smcList[[i]])) ) stop("list objects are not of class mcmcSampler")
}
class(smcList) = c("smcSamplerList", "bayesianOutput")
return(smcList)
}

#' @method summary smcSamplerList
#' @author Florian Hartig
#' @export
summary.smcSamplerList <- function(object, ...){
sample = getSample(object, parametersOnly = T, ...)
summary(sample)
}

#' @method print smcSamplerList
#' @author Florian Hartig
#' @export
print.smcSamplerList <- function(x, ...){
print("smcSamplerList - you can use the following methods to summarize, plot or reduce this class:")
print(methods(class ="smcSamplerList"))
}

#' @method plot smcSamplerList
#' @export
plot.smcSamplerList <- function(x, ...){
marginalPlot(x, ...)
}

#' @export
getSample.smcSamplerList <- function(sampler, parametersOnly = T, coda = F, start = 1, end = NULL, thin = 1,
numSamples = NULL, whichParameters = NULL, reportDiagnostics = FALSE, ...){

out = list()

for (i in 1:length(sampler)){

out[[i]] = getSample(sampler[[i]], parametersOnly = parametersOnly, whichParameters = whichParameters, start = start, end = end, thin = thin,
numSamples = numSamples, coda = F, reportDiagnostics = F)

}
out = combineChains(out, merge =F)

return(out)
}