Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
6ccf229
distance function
florianhartig Jul 13, 2018
884f431
Merge branch 'master' into SMC
florianhartig Jul 16, 2018
df5ad1f
Merge branch 'master' into SMC
florianhartig Jul 31, 2018
b17e112
updates to SMC
florianhartig Jul 31, 2018
7c021d4
Specified numerical tolerance parameter to avoid crashes
mspeich Aug 1, 2018
0c34c9b
Modify particle resampling scheme
mspeich Aug 1, 2018
83ef7b5
Add basic Differential Evolution option for SMC
mspeich Aug 7, 2018
8513066
Fix updating of surviving particles
mspeich Aug 7, 2018
6fe7239
SMC tests
florianhartig Aug 9, 2018
668d2d2
SMC function changes
florianhartig Aug 9, 2018
f9f6733
updates test
florianhartig Aug 9, 2018
87fce94
smc updates
florianhartig Aug 10, 2018
d0a3d84
Fix some SMC issues
mspeich Aug 16, 2018
96086e4
Fix algorithm for adaptive sequence
mspeich Aug 20, 2018
93becbe
Fix differential evolution mutate step
mspeich Aug 28, 2018
804e195
Some unit tests for SMC
mspeich Aug 28, 2018
648e949
Add more diagnostic outputs to SMC
mspeich Aug 28, 2018
5960ac5
Combine resample and mutate steps
mspeich Aug 28, 2018
175a893
Allow SIR without mutation
mspeich Aug 29, 2018
f5710a1
Add more unit tests for SMC
mspeich Aug 29, 2018
3465ae1
Lower tolerance criterion to avoid crash of Bhattacharyya distance fu…
mspeich Oct 8, 2018
93da416
Improve proposal function of MCMC kernel
mspeich Oct 8, 2018
a3535f5
Add possibility to get two output terms for Bhattacharyya distance
mspeich Oct 16, 2018
25981c4
Allow 2 output terms for diagnostic function
mspeich Oct 16, 2018
c90cff2
Suppress print
mspeich Oct 16, 2018
72ec8ef
Fix code for Distance (type "D")
mspeich Nov 5, 2018
0245c0a
changed runtimeto info slot
Nov 13, 2018
57eabae
update to sample distance help
Nov 13, 2018
9a3f291
write runtime info to info slot
Nov 13, 2018
227d047
Temporary changes for debugging
mspeich Nov 13, 2018
e28774a
Merge branch 'SMC' of https://github.com/florianhartig/BayesianTools …
mspeich Nov 13, 2018
7f5c81b
Temporary outputs for debugging
mspeich Nov 13, 2018
a5ec62f
Temporary debug output
mspeich Nov 14, 2018
6920269
Merge branch 'master' into SMC
Nov 14, 2018
fcd3197
distance help update
Nov 14, 2018
ed6577b
Merge branch 'master' into SMC
Nov 19, 2018
8634646
Temporary debug output
mspeich Nov 20, 2018
c9765cd
Merge branch 'SMC' of https://github.com/florianhartig/BayesianTools …
mspeich Nov 20, 2018
5e4165f
Fix temporary debug output
mspeich Nov 20, 2018
84980d1
Merge branch 'master' into SMC
Nov 22, 2018
1f81787
Merge branch 'master' into SMC-Merge
Jul 31, 2019
1342d58
Merge branch 'master' into SMC-Merge
florianhartig Apr 19, 2021
6237775
Updated help / documentation
florianhartig Apr 19, 2021
3fed011
help updates
florianhartig Apr 19, 2021
9329358
Merge branch 'master' into SMC-Merge
florianhartig Apr 20, 2021
b87c0b6
integration in runMCMC and help updates
florianhartig Apr 20, 2021
174a202
Expand parameter descriptions for SMC function
mspeich Apr 21, 2021
84e1ead
Add script to plot SMC output
mspeich Apr 21, 2021
4bbfb4e
Update SMC.R
florianhartig Apr 22, 2021
63f42ff
updated parameter sequence in help
florianhartig Apr 22, 2021
ccca96f
Update SMC.R
florianhartig Jul 10, 2021
a41eaa8
Merge branch 'master' into SMC-Merge
florianhartig Mar 8, 2026
f304761
Merge branch 'master' into SMC-Merge
florianhartig Mar 8, 2026
65d712d
updates
florianhartig Mar 8, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions BayesianTools/NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export(getPossibleSamplerTypes)
export(getPredictiveDistribution)
export(getPredictiveIntervals)
export(getSample)
export(getSampleDistance)
export(getVolume)
export(likelihoodAR1)
export(likelihoodIidNormal)
Expand Down
33 changes: 12 additions & 21 deletions Test/Distance.R → BayesianTools/R/Distance.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@
#' BH = Bhattacharyya distance
#' D = normalized Euclidean distance between mean and standard deviation of sample and target. Not symmetric. Target is sample 1. This was described in eq. 10 in Laloy, E., and J. A. Vrugt. 2012. High-dimensional posterior exploration of hydrologic models using multiple-try DREAM(ZS) and high-performance computing. Water Resour. Res. 48(1)
#'
#' @example /inst/examples/getSampleDistanceHelp.R
#' @export
#'
getSampleDistance <- function(sample1, sample2, type = "KL"){

if(type == "KL"){
library(FNN) # I'm keeping this at the moment to throw an error if FNN is not installed
x = FNN::KL.dist(sample1, sample2, k=10)
out = mean(x) # FH: no idea if the mean is a good idea. KL.dist returns one value per cluster size, I don't know which value is best chosen

} else if(type == "BH" ){
} else if(type == "BH" | type == "BHs" ){
Sigma1 = cov(sample1)
Sigma2 = cov(sample2)
mu1 = colMeans(sample1)
Expand All @@ -27,10 +30,14 @@ getSampleDistance <- function(sample1, sample2, type = "KL"){
# The following code is copied from package fpc

aggregatesigma <- (Sigma1+Sigma2)/2
d1 <- mahalanobis(mu1,mu2,aggregatesigma)/8
d2 <- log(det(as.matrix(aggregatesigma))/sqrt(det(as.matrix(Sigma1))*
det(as.matrix(Sigma2))))/2
#d1 <- mahalanobis(mu1,mu2,aggregatesigma,tol=1e-20)/8 # tol (tolerance) argument gets passed to solve(). Avoids crashes if there are very small values in the covariance matrices
d1 <- mahalanobis(mu1,mu2,aggregatesigma,tol=.Machine$double.xmin)/8 # tol (tolerance) argument gets passed to solve(). Avoids crashes if there are very small values in the covariance matrices
d2 <- log(det(as.matrix(aggregatesigma))/sqrt(det(as.matrix(Sigma1))*det(as.matrix(Sigma2))))/2
if(type == "BH"){
out <- d1+d2
} else if (type == "BHs"){
out <- c(d1, d2)
}

# end fpc

Expand All @@ -42,7 +49,7 @@ getSampleDistance <- function(sample1, sample2, type = "KL"){
sd2 = apply(sample2, 2, sd)
mu1 = colMeans(sample1)
mu2 = colMeans(sample2)
dev = sum( ((mu1 - mu2)/sd1)^2 + ((mu1 - mu2)/sd1)^2 )
dev = sum( ((mu1 - mu2)/sd1)^2 + ((sd1 - sd2)/sd1)^2 )

out = sqrt( 1/(2*length(mu1)) * dev )

Expand Down Expand Up @@ -72,23 +79,7 @@ getSampleDistance <- function(sample1, sample2, type = "KL"){
#'


library(mvtnorm)

sigma <- matrix(c(4,2,2,3), ncol=2)
X <- rmvnorm(n=2500, mean=c(1,2), sigma=sigma)
X = rbind(X,X)
Y <- rmvnorm(n=2500, mean=c(5,2), sigma=sigma)
Y = rbind(Y,X)

FNN::KL.dist(X, Y, k=10)

X = getSample(out, start = 1000, end = 2000)
Y = getSample(out, start = 2000, end = 3000)


getSampleDistance(X,Y, type = "KL")
getSampleDistance(X,Y, type = "BH")
getSampleDistance(X,Y, type = "D")



Loading
Loading