Skip to content

Commit

Permalink
Merge branch 'master' into BayesianSetupUpdateParallel
Browse files Browse the repository at this point in the history
  • Loading branch information
florianhartig authored Nov 8, 2023
2 parents 96e1312 + eef2476 commit 6575b1c
Show file tree
Hide file tree
Showing 13 changed files with 372 additions and 324 deletions.
23 changes: 23 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto

# Explicitly declare text files you want to always be normalized and converted
# to native line endings on checkout.
*.Rd text
*.Rmd text
*.R text
*.r text
*.Rproj text
*.[Rr]md linguist-detectable
*.yml text


# Denote all files that are truly binary and should not be modified.
*.Rdata binary
*.RData binary
*.rda binary
*.rdb binary
*.rds binary
*.png binary
*.jpg binary
*.Rdx binary
8 changes: 4 additions & 4 deletions BayesianTools/CRAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ This file contains CRAN submission info / communication

### Submission 1

This is minor update should re-instate BT to CRAN, after it was removed due to HTML validation problems connected to the recent switch to HTML5 for documentation pages in R 4.2.0, see also https://github.com/florianhartig/BayesianTools/issues/240.
This is a minor update that should bring BT back to CRAN after it was removed due to HTML validation problems associated with the recent switch to HTML5 for documentation pages in R 4.2.0, see also https://github.com/florianhartig/BayesianTools/issues/240.

I had tried to upload a fix to CRAN, which, however, was not accepted due to detritus problems under Windows dev, which, after a long search, turned up to be caused by some stray parallel notes https://github.com/florianhartig/BayesianTools/issues/244
I had tried to upload a fix to CRAN, but it was not accepted due to detritus problems under Windows dev, which after a long search turned out to be caused by some stray parallel notes https://github.com/florianhartig/BayesianTools/issues/244.

In any case, I hope this will re-instate the BT package to CRAN, sorry for the delay in fixing this.
In any case, I hope this will get the BT package back into CRAN, sorry for the delay in fixing this.

See NEWS for other changes.

This release was tested without apparent problems under
This release has been tested without apparent problems on

* local MAC OS 13.1, R 4.2.1 Apple
* http://win-builder.r-project.org/ - oldrelease / devel / release
Expand Down
2 changes: 1 addition & 1 deletion BayesianTools/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Title: General-Purpose MCMC and SMC Samplers and Tools for Bayesian Statistics
Version: 0.1.8
Date: 2023-01-30
Authors@R: c(person("Florian", "Hartig", email = "[email protected]", role = c("aut", "cre"), comment=c(ORCID="0000-0002-6255-9059")), person("Francesco", "Minunno", role = c("aut")), person("Stefan", " Paul", role = c("aut") ), person("David", "Cameron", role = "ctb"), person("Tankred", "Ott", role = "ctb"), person("Maximilian", "Pichler", role = "ctb"))
Description: General-purpose MCMC and SMC samplers, as well as plot and
Description: General-purpose MCMC and SMC samplers, as well as plots and
diagnostic functions for Bayesian statistics, with a particular focus on
calibrating complex system models. Implemented samplers include various
Metropolis MCMC variants (including adaptive and/or delayed rejection MH), the
Expand Down
1 change: 1 addition & 0 deletions BayesianTools/R/BayesianTools.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#' @title BayesianTools
#' @name BayesianTools
#' @aliases BayesianTools-package
#' @docType package
#' @useDynLib BayesianTools, .registration = TRUE
#' @description A package with general-purpose MCMC and SMC samplers, as well as plots and diagnostic functions for Bayesian statistics
Expand Down
12 changes: 7 additions & 5 deletions BayesianTools/R/classMcmcSampler.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ getSample.mcmcSampler <- function(sampler, parametersOnly = T, coda = F, start =
#' @method summary mcmcSampler
#' @author Stefan Paul
#' @export
summary.mcmcSampler <- function(object, ...){
summary.mcmcSampler <- function(object, printCorrelation = "auto", ...){
#codaChain = getSample(sampler, parametersOnly = parametersOnly, coda = T, ...)
#summary(codaChain)
#rejectionRate(sampler$codaChain)
Expand All @@ -133,8 +133,7 @@ summary.mcmcSampler <- function(object, ...){

mcmcsampler <- sampler$settings$sampler
runtime <- sampler$settings$runtime[3]
correlations <- round(cor(getSample(sampler)),3)


chain <- getSample(sampler, parametersOnly = T, coda = T, ...)
# chain <- getSample(sampler, parametersOnly = T, coda = T)
if("mcmc.list" %in% class(chain)){
Expand Down Expand Up @@ -203,8 +202,11 @@ summary.mcmcSampler <- function(object, ...){

try(cat("## DIC: ", round(DInf$DIC,3), "\n"), silent = TRUE)
cat("## Convergence" ,"\n", "Gelman Rubin multivariate psrf: ", conv, "\n","\n")
cat("## Correlations", "\n")
print(correlations)
if(printCorrelation == TRUE){
correlations <- round(cor(getSample(sampler)),3)
cat("## Correlations", "\n")
print(correlations)
}
}

#' @author Florian Hartig
Expand Down
25 changes: 24 additions & 1 deletion BayesianTools/R/mcmcRun.R
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,30 @@ runMCMC <- function(bayesianSetup , sampler = "DEzs", settings = NULL){
#' @param settings optional list with parameters that will be used instead of the defaults
#' @param sampler one of the samplers in \code{\link{runMCMC}}
#' @param check logical determines whether parameters should be checked for consistency
#' @details see \code{\link{runMCMC}}
#' @details
#'
#' The following settings can be used for all MCMCs:
#'
#' startValue (no default) start values for the MCMC. Note that DE family samplers require a matrix of #' start values. If startvalues are not provided, they are sampled from the prior.
#'
#' iterations (10000) the MCMC iterations
#'
#' burnin (0) burnin
#'
#' thin (1) thinning while sampling
#'
#' consoleUpdates (100) update frequency for console updates
#'
#' parallel (NULL) whether parallelization is to be used
#'
#' message (TRUE) if progress messages are to be printed
#'
#' nrChains (1) the number of independent MCMC chains to be run. Note that this is not controlling the #' internal number of chains in population MCMCs such as DE, so if you run nrChains = 3 with a DEzs #' #' startValue that is a 4xparameter matrix (= 4 internal chains), you will run independent DEzs runs #' #' with 4 internal chains each.
#'
#' For more details, see \code{\link{runMCMC}}
#'
#'
#' @example inst/examples/mcmcRun.R
#' @export
applySettingsDefault<-function(settings=NULL, sampler = "DEzs", check = FALSE){

Expand Down
4 changes: 2 additions & 2 deletions BayesianTools/R/plotMarginals.R
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ marginalPlotDensity <- function(posteriorMat, priorMat = NULL, xrange = NULL, co
mtext('Marginal parameter uncertainty', outer = TRUE, cex = 1.5)

} else {
mfrow <- if (nPar < 16) getPanels(nPar) else c(4,4)
mfrow <- getPanels(nPar)

op <- par(mfrow = mfrow, mar = c(4.5, 4, 5, 3), oma=c(3, 1.5, 2, 0), xpd=TRUE)
on.exit(par(op))
Expand Down Expand Up @@ -282,7 +282,7 @@ marginalPlotViolin <- function(posteriorMat, priorMat = NULL, xrange = NULL, col
mtext('Marginal parameter uncertainty', outer = TRUE, cex = 1.5)

} else {
mfrow <- if (nPar < 16) getPanels(nPar) else c(4,4)
mfrow <- getPanels(nPar)

op <- par(mfrow = mfrow, mar = c(4.5, 4.5, 5, 3), oma=c(3, 0, 2, 0), xpd=TRUE)

Expand Down
7 changes: 5 additions & 2 deletions BayesianTools/inst/examples/mcmcRun.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ ll <- generateTestDensityMultiNormal(sigma = "no correlation")
## is the recommended way of using the runMCMC() function.
bayesianSetup <- createBayesianSetup(likelihood = ll, lower = rep(-10, 3), upper = rep(10, 3))

## Finally we can run the sampler and have a look
settings = list(iterations = 1000, adapt = FALSE)
## Finally we can run the sampler. To get possible settings
## for a sampler, see help or run applySettingsDefault(sampler = "Metropolis")
settings = list(iterations = 1000, adapt = FALSE) #
out <- runMCMC(bayesianSetup = bayesianSetup, sampler = "Metropolis", settings = settings)

## out is of class bayesianOutput. There are various standard functions
Expand All @@ -21,3 +22,5 @@ summary(out)
# for plotting and analysis

codaObject = getSample(out, start = 500, coda = TRUE)


1 change: 1 addition & 0 deletions BayesianTools/man/BayesianTools.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 47 additions & 1 deletion BayesianTools/man/applySettingsDefault.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions BayesianTools/man/runMCMC.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6575b1c

Please sign in to comment.