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

Bsm merge again #307

Open
wants to merge 102 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
9932c84
start working on adding reweighting options for hadron
pittlerf Sep 26, 2019
b0ed038
rw_orig added
pittlerf Sep 26, 2019
9b67c8b
reading function for reweighting factor
pittlerf Sep 26, 2019
b678374
Correcting errors
pittlerf Sep 27, 2019
3dc4bfa
correcting errors
pittlerf Sep 27, 2019
c1eb13c
adding possibility to reverse correlation functions
pittlerf Sep 28, 2019
754d287
correcting errors
pittlerf Sep 29, 2019
4b26f9f
renaming and error search
pittlerf Sep 30, 2019
12f0654
corrected errors
pittlerf Sep 30, 2019
add1d1a
after multiplying two reweighting factors, you could not increase sta…
pittlerf Sep 30, 2019
32e577a
correcting error
pittlerf Sep 30, 2019
bed0b43
Implementing reweighting: setting the bootstrap or jackknife samples …
pittlerf Sep 30, 2019
b88a01a
removing testing print statements
pittlerf Sep 30, 2019
95e7ce7
correcting errors
pittlerf Sep 30, 2019
7275044
Performing gauge conf list check in reweighting
pittlerf Oct 1, 2019
c9aa2a5
Including it in jackknife as well
pittlerf Oct 1, 2019
a871557
Typo corrected
pittlerf Oct 1, 2019
6e6664d
Specify dependency on dplyr
pittlerf Oct 2, 2019
ed4879c
function that averages correlation functions just over the stochastic…
pittlerf Oct 2, 2019
b35557c
Comparing two vectors with identical()
pittlerf Oct 2, 2019
1240d30
by mistake I have deleted man/addStat.cf.Rd
pittlerf Oct 2, 2019
191f0ba
Errors for Rd file jackknife corrected
pittlerf Oct 2, 2019
430be22
Errors for Rd file cf_boot corrected
pittlerf Oct 2, 2019
08ef589
Further errors corrected
pittlerf Oct 2, 2019
0bbd5a2
Correct cf_boot
pittlerf Oct 2, 2019
fc6e7dd
additional Rd files uploaded
pittlerf Oct 2, 2019
1cf72f3
removing averaging over stochastic samples
pittlerf Oct 3, 2019
17c3058
correcting the appropriate man file as well
pittlerf Oct 3, 2019
81db664
correcting for the behaviour of is.na in if statement
pittlerf Oct 3, 2019
0dda8b2
correcting testing for icf
pittlerf Oct 3, 2019
548eb99
Simplifying bootstrap_rwcf and jackknife_rwcf
pittlerf Oct 8, 2019
0fb2b42
Using functions from branch icf_support
pittlerf Nov 8, 2019
f17f73a
input parameter types for jackknife_rw.cf
pittlerf Nov 8, 2019
2cf8814
Adding more clarifications and correcting typo
pittlerf Nov 8, 2019
0d5ab14
Merge pull request #195 from HISKP-LQCD/icf_support
pittlerf Nov 8, 2019
865dcaf
Merge remote-tracking branch 'origin/origin/reweighting' into origin/…
pittlerf Nov 12, 2019
74b3f53
try to upload modifications
pittlerf Nov 12, 2019
67ad0c1
Consistent assignments
pittlerf Nov 12, 2019
25e64dc
mixin reintroducted
pittlerf Nov 12, 2019
284c9dd
Example for addStat.cf documentation
pittlerf Nov 12, 2019
dd99b7c
the same explanation for combining replicas for reweighting factors
pittlerf Nov 12, 2019
184f86e
including dplyr in DESCRIPTION
pittlerf Nov 12, 2019
bd71437
for names of columns in reweighting factor made some explanations
pittlerf Nov 12, 2019
dbcbe71
remove default argument for conf.index
pittlerf Nov 12, 2019
567e108
Rd files added
pittlerf Nov 12, 2019
d60a89e
adding red colors for plotting negativ values
pittlerf Nov 12, 2019
f93326d
uploading Rd file
pittlerf Nov 12, 2019
b3d9073
correcting names of columns in tmp
pittlerf Nov 13, 2019
87f6dd2
started to implement PLEGMA readers for baryon correlation function
pittlerf Nov 13, 2019
b226aa5
Finalize merging
pittlerf Nov 14, 2019
7e0d32d
trying to fix conflicts
pittlerf Nov 26, 2019
4140e6e
trying to fix conflicts
pittlerf Nov 26, 2019
6d6d7ae
trying to correct conflicts
pittlerf Nov 26, 2019
4f9111e
trying to fix conflicts
pittlerf Nov 26, 2019
d64dec0
resolving conflicts
pittlerf Nov 26, 2019
266da59
resolving conflicts again
pittlerf Nov 26, 2019
603f177
resolve intergration error
pittlerf Nov 26, 2019
a714c51
adding errors in plotting the reweighting factors
pittlerf Nov 26, 2019
ea0b6e6
changing back to roxygen700
pittlerf Nov 26, 2019
b43b5d3
fixing conflicts
pittlerf Nov 26, 2019
aa378e9
resolving integration test further
pittlerf Nov 26, 2019
71bbeb8
Removing str
pittlerf Nov 26, 2019
ae63ad6
Merge branch 'origin/reweighting' into plegmareading
pittlerf Nov 28, 2019
9f6df2f
Adding reading routine for baryon correlation functions
pittlerf Nov 28, 2019
bdc0043
Adding reading routine for baryon correlation functions
pittlerf Nov 28, 2019
af37e10
including symmetrization in baryon reading
pittlerf Nov 29, 2019
9d68e21
additional dependency added
pittlerf Nov 29, 2019
8a1a20c
typo-s corrected
pittlerf Nov 29, 2019
e7b1479
reading baryon correlation function now direvtly in cf type, later in…
pittlerf Dec 2, 2019
9324194
add function for computing GL FSE correction factors
kostrzewa Feb 20, 2020
0444b7b
remove outdated documentation and unnecessary parameters from gl_fse_…
kostrzewa Feb 21, 2020
1327fce
merging with master
pittlerf Apr 29, 2020
48f5864
removing compilation error
pittlerf Apr 29, 2020
7d13238
reading 2pt functions for piN scattering
pittlerf May 4, 2020
68b880e
optimazition of the reading routin
pittlerf May 5, 2020
8b021db
Adding symmetrization to the baryon correlation function for scatteri…
pittlerf May 6, 2020
6855836
reading of the B,W,Z diagramms
pittlerf May 8, 2020
f4d39b1
correcting bugs
pittlerf May 8, 2020
12b9ffa
Merge tag '3.1.0' into HEAD
pittlerf May 26, 2020
33b0f4f
correcting bug
pittlerf Jun 12, 2020
03e5cf8
updating calc2pt baryon correlation function key
pittlerf Jun 18, 2020
3a24628
Merge branch 'plegmareading' of github.com:HISKP-LQCD/hadron into HEAD
pittlerf Jun 18, 2020
5a06ed1
modifying the key according to new format
pittlerf Jun 20, 2020
12c0956
Merge remote-tracking branch 'origin' into HEAD
pittlerf Jun 20, 2020
9f626a4
reading files containing all the gauge configuartions
pittlerf Jun 23, 2020
d07f473
removing separate reading 4pt,2pt, now just one general reading routi…
pittlerf Jul 14, 2020
c61f28c
addign namespace as well
pittlerf Jul 14, 2020
d965f4c
Merge remote-tracking branch 'origin/master' into gl_fse
kostrzewa Jul 18, 2020
63b98c1
fit model for single and multiple baryons are added, with simple expo…
pittlerf Sep 29, 2020
3aa936f
correcting baryon correlation function reader, we only read already p…
pittlerf Sep 29, 2020
02c9c93
doing the merge with current master
pittlerf Sep 29, 2020
7543f68
erge remote-tracking branch 'origin' into HEAD
pittlerf Sep 29, 2020
6b3767a
Merge remote-tracking branch 'origin/gl_fse' into HEAD
pittlerf Sep 29, 2020
a311538
correcting errors
pittlerf Nov 11, 2020
5a0bb00
Solving the gevp even when the matrix C(t0) is not positive definite
pittlerf Apr 20, 2021
01bd639
merging the bsm_readutils branch with my current hadron
pittlerf May 5, 2021
7dcf226
finalizing the merge
pittlerf May 6, 2021
3c1ba1a
merging with plegmareading_develop
pittlerf May 6, 2021
db39c09
finalizing merge
pittlerf May 6, 2021
c1a0d83
Merge remote-tracking branch 'origin/master' into bsm_merge
kostrzewa Mar 17, 2022
09dc280
the documentation is now auto-generated
kostrzewa Mar 17, 2022
63fea02
NAMESPACE file auto-generated
kostrzewa Mar 17, 2022
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 DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Description: Toolkit to perform statistical analyses of correlation
<https://inspirehep.net/literature/1792113>) are implemented.
In addition, input/output and plotting routines are available.
Imports:
dplyr,
abind,
boot,
dplyr,
Expand Down
253 changes: 227 additions & 26 deletions R/cf.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ cf_meta <- function (.cf = cf(), nrObs = 1, Time = NA, nrStypes = 1, symmetrised
return (.cf)
}

#' Bootstrapped CF mixin constructor

#' Bootstrapped CF mixin constructor
#'
#' @param .cf `cf` object to extend.
#' @param boot.R Integer, number of bootstrap samples used.
Expand Down Expand Up @@ -126,6 +127,7 @@ cf_boot <- function (.cf = cf(), boot.R, boot.l, seed, sim, endcorr, cf.tsboot,
return (.cf)
}


#' Estimates error from jackknife samples
#'
#' Currently this uses the mean over the jackknife samples in order to compute
Expand Down Expand Up @@ -497,10 +499,78 @@ gen.block.array <- function(n, R, l, endcorr=TRUE) {
return(list(starts = st, lengths = lens))
}

#' Computes the samples for reweighted correlation function
#'
#' @param cf `cf` object.
#' @param rw `rw` object.
#' @param boot.R Integer
#' @param boot.l Integer
#' @param seed Integer
#' @param sim string
#' @param endcorr boolean
#' @export
bootstrap_rw.cf <- function(cf, rw, boot.R=400, boot.l=2, seed=1234, sim="geom", endcorr=TRUE) {
stopifnot(inherits(cf, 'cf_orig'))
stopifnot(inherits(rw, 'rw_orig'))
stopifnot(inherits(rw, 'rw_meta'))
stopifnot(inherits(cf, 'cf_indexed'))


#' bootstrap a set of correlation functions
#'
##We should also check that the cf object and the rw object contains the same gauge configurations

stopifnot(rw$conf.index == cf$conf.index)

stopifnot( nrow(cf$cf) == length(rw$conf.index) )

boot.l <- ceiling(boot.l)
boot.R <- floor(boot.R)

stopifnot(boot.l >= 1)
stopifnot(boot.l <= nrow(cf$cf))
stopifnot(boot.R >= 1)

##Construct correlation function for the reweighting samples
rw_cf <- cf
rw_cf$cf <- replicate(ncol(cf$cf), rw$rw)

## we set the seed for reproducability and correlation
old_seed <- swap_seed(seed)

## now we bootstrap the correlators*reweighting factor
rwcf.tsboot <- boot::tsboot(cf$cf*rw_cf$cf, statistic = function(x){ return(apply(x, MARGIN=2L, FUN=mean))},
R = boot.R, l=boot.l, sim=sim, endcorr=endcorr)


restore_seed(old_seed)

## we set the seed for reproducability and correlation
old_seed <- swap_seed(seed)

## now we bootstrap the reweighting factor
rw.tsboot <- boot::tsboot(rw_cf$cf, statistic = function(x){ return(apply(x, MARGIN=2L, FUN=mean))},
R = boot.R, l=boot.l, sim=sim, endcorr=endcorr)


rwcf.tsboot$t0<- rwcf.tsboot$t0/rw.tsboot$t0
rwcf.tsboot$t <- rwcf.tsboot$t/rw.tsboot$t

cf <- cf_boot(cf,
boot.R = boot.R,
boot.l = boot.l,
seed = seed,
sim = sim,
cf.tsboot = rwcf.tsboot)

class(cf) <- append(class(cf), 'cfrw_boot')

class(cf) <- setdiff(class(cf), 'cf_orig')


restore_seed(old_seed)

return(invisible(cf))
}

#' bootstrap a set of correlation functions
#'
#'
Expand Down Expand Up @@ -574,9 +644,6 @@ bootstrap.cf <- function(cf, boot.R=400, boot.l=2, seed=1234, sim="geom", endcor
}



#' jackknife a set of correlation functions
#'
#' jackknife a set of correlation functions
#'
#'
Expand Down Expand Up @@ -666,8 +733,83 @@ jackknife.cf <- function(cf, boot.l = 1) {
resampling_method = 'jackknife')

return (invisible(cf))

}

#' Computes the jackknife samples for reweighted correlation function
#'
#' @param cf `cf` object.
#' @param rw `rw` object.
#' @param boot.l Integer
#' @export
jackknife_rw.cf <- function(cf, rw, boot.l = 1) {
stopifnot(inherits(cf, 'cf_orig'))
stopifnot(inherits(rw, 'rw_orig'))
stopifnot(inherits(rw, 'rw_meta'))
stopifnot(inherits(cf, 'cf_indexed'))

stopifnot(rw1$conf.index == rw2$conf.index)

##We should also check that the cf object and the rw object contains the same gauge configurations

stopifnot( nrow(cf$cf) == length(rw$conf.index) )


stopifnot(boot.l >= 1)
boot.l <- ceiling(boot.l)

##Construct correlation function for the reweighting samples
rw_cf <- cf
rw_cf$cf <- replicate(ncol(cf$cf), rw$rw)


## blocking with fixed block length, but overlapping blocks
## number of observations
n <- nrow(cf$cf)
## number of overlapping blocks
N <- n-boot.l+1


numerator <- apply(cf$cf*rw_cf$cf, 2, mean)
denominator <- apply(rw_cf$cf, 2, mean)
t0 <- numerator/denominator

t <- array(NA, dim = c(N, ncol(cf$cf)))
for (i in 1:N) {
## The measurements that we are going to leave out.
ii <- c(i:(i+boot.l-1))
## jackknife replications of the mean
t[i, ] <-

numerator <- apply(cf$cf[-ii, ]* rw_cf$cf[ ii, ], 2L, mean)
denominator <- apply( rw_cf$cf[ ii, ] , 2L, mean )
t[i, ] < numerator/denominator
}


cf <- invalidate.samples.cf(cf)

cf.tsboot <- list(t = t,
t0 = t0,
R = N,
l = boot.l)


cf <- cf_boot(cf,
boot.R = cf.tsboot$R,
boot.l = cf.tsboot$l,
seed = 0,
sim = 'geom',
cf.tsboot = cf.tsboot,
resampling_method = 'jackknife')

class(cf) <- append(class(cf), 'cfrw_boot')

class(cf) <- setdiff(class(cf), 'cf_orig')

return (invisible(cf))
}
# Gamma method analysis on all time-slices in a 'cf' object
#' uwerr.cf
#' @description
#' Gamma method analysis on all time-slices in a 'cf' object
Expand Down Expand Up @@ -738,26 +880,20 @@ addConfIndex2cf <- function(cf, conf.index) {
if(is.null(cf$conf.index)) {
cf$conf.index <- conf.index
}
class(cf) <- append(class(cf), 'cf_indexed')
return(cf)
}



#' Combine statistics of two cf objects
#'
#' \code{addStat.cf} takes the raw data of two \code{cf} objects and combines
#' them into one
#' Combine correlation function from different replicas
#'
#' Note that the two \code{cf} objects to be combined need to be compatible.
#' Otherwise, \code{addStat.cf} will abort with an error.
#'
#' @param cf1 the first of the two \code{cf} objects to be combined
#' @param cf2 the second of the two \code{cf} objects to be combined
#' @return an object of class \code{cf} with the statistics of the two input
#' \code{cf} objects combined
#' @author Carsten Urbach, \email{curbach@@gmx.de}
#' @seealso \code{\link{cf}}
#' @keywords correlation function
#' @param cf1 `cf` object: correlation function for replicum A
#' @param cf2 `cf` object: correlation function for replicum B
#' @param reverse1 `boolean` After the bifurcation point one of
#' the replicas (chain of correlation
#' functions in simulation time) has
#' to be reversed.
#' @param reverse2 `boolean`
#'
#' @examples
#'
#' data(samplecf)
Expand All @@ -766,7 +902,7 @@ addConfIndex2cf <- function(cf, conf.index) {
#' cfnew <- addStat.cf(cf1=samplecf, cf2=samplecf)
#'
#' @export
addStat.cf <- function(cf1, cf2) {
addStat.cf <- function(cf1, cf2, reverse1=TRUE,reverse2=FALSE) {
stopifnot(inherits(cf1, 'cf'))
stopifnot(inherits(cf2, 'cf'))

Expand All @@ -780,15 +916,47 @@ addStat.cf <- function(cf1, cf2) {
stopifnot(inherits(cf1, 'cf_meta'))
stopifnot(inherits(cf2, 'cf_meta'))

##Either both should have an index or none of them
stopifnot(inherits(cf1, 'cf_indexed') == inherits(cf1, 'cf_indexed') )

stopifnot(cf1$Time == cf2$Time)
stopifnot(dim(cf1$cf)[2] == dim(cf2$cf)[2])
stopifnot(cf1$nrObs == cf2$nrObs )
stopifnot(cf1$nrStypes == cf2$nrStypes)

cf <- cf1

cf$cf <- rbind(cf1$cf, cf2$cf)
cf$icf <- rbind(cf1$icf, cf2$icf)
cf1_temp<- cf1$cf
icf1_temp <- cf1$icf
if (reverse1 == TRUE){
apply(cf1_temp,2,rev)
if ( has_icf(cf1)){
apply(icf1_temp,2,rev)
}
}
cf2_temp <- cf2$cf
icf2_temp <- cf2$icf
if (reverse2 == TRUE){
apply(cf2_temp,2,rev)
if ( has_icf(cf2)){
apply(icf2_temp,2,rev)
}
}
if (inherits(cf1, 'cf_indexed')){
conflist_temp1 <- cf1$conf.index
if (reverse1 == TRUE){
conflist_temp1 <- rev(conflist_temp1)
}
conflist_temp2 <- cf2$conf.index
if (reverse2 == TRUE){
conflist_temp2 <- rev(conflist_temp2)
}
cf$conf.index <- c(conflist_temp1,conflist_temp2)
}


cf$cf <- rbind(cf1_temp, cf2_temp)
cf$icf <- rbind(icf1_temp, icf2_temp)

cf <- invalidate.samples.cf(cf)

Expand Down Expand Up @@ -958,7 +1126,6 @@ apply_elementwise.cf <- function(cf1, cf2, `%op%` = `/`) {
stopifnot(cf1$Time == cf2$Time)

cf$cf <- cf1$cf %op% cf2$cf

if( has_icf(cf1) | has_icf(cf2) ){
stopifnot(has_icf(cf1) & has_icf(cf2))
cf$icf <- cf1$icf %op% cf2$icf
Expand Down Expand Up @@ -1317,6 +1484,40 @@ shift.cf <- function(cf, places) {
return(invisible(cf))
}


avg.sparsify.cf <- function(cf, avg, sparsity){
if(!any(class(cf) == "cf")) {
stop("avg.sparsify.cf: Input must be of class 'cf'\n")
}
if( sparsity > 1 ){
stop("avg.sparsify.cf: Sparsification has not been implemented yet, only sparsity = 1 supported for now.\n")
}

Lt <- cf$Time
if(cf$symmetrised){
Lt <- cf$Time/2 + 1
}
nmeas <- length(cf$cf) / Lt
targetstats <- nmeas / avg

cf2 <- invalidate.samples.cf(cf)
cf2$cf <- cf$cf[(1:targetstats),]
cf2$icf <- cf$icf[(1:targetstats),]

for( m_idx in 1:targetstats ){
from <- (m_idx-1)*avg + 1
to <- m_idx*avg
avg_idx <- c(from:to)
cf2$cf[m_idx,] <- apply(X = cf$cf[avg_idx,],
MARGIN = 2,
FUN = sum)/avg
#cf2$icf[m_idx,] <- apply(X = cf$icf[avg_idx,],
# MARGIN = 2,
# FUN = sum)/avg
}
return(cf2)
}

#' Invalidate samples
#'
#' When a correlation function is modified, any resampling should be
Expand Down
Loading