Skip to content
Open
Changes from 3 commits
Commits
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
100 changes: 100 additions & 0 deletions R/cf.R
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,106 @@ mul.cf <- function(cf, a=1.) {
return (cf)
}

#' Exponentiate cf objects
#'
#' Note that no complex arithmetic is used, real and imaginary parts are
#' treated as seperate and indepenent, such that the real part of cf is
#' raised to the power of n and similarly for the imaginary part.
#'
#' Note that this is generally only allowed on bootstrap samples and mean values,
#' although it makes sense in some exeptional circumstances. Don't use this
#' function unless you're certain that you should!
#'
#' @param cf `cf_orig` object.
#' @param n Numeric.
#'
#' @return
#' The value is
#' \deqn{cf^n \,.}
#' @export
pow.cf <- function(cf, n=1.) {
stopifnot(inherits(cf, 'cf_meta'))
if(inherits(cf, 'cf_orig')) {
cf$cf <- (cf$cf)^n

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you actually want to take a power of the original data or is this an operation which should only be carried out on the mean value and bootstrap samples?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to take a power of the original data to keep the function as general as possible. However, in my analysis I passed bootstrapped correlation functions to this function.


if( has_icf(cf) ){
stopifnot(has_icf(cf))
Comment thread
NikSchlage marked this conversation as resolved.
Outdated
cf$icf <- (cf$icf)^n
}
}

if(inherits(cf, 'cf_boot')) {
cf$cf.tsboot$t <- (cf$cf.tsboot$t)^n
cf$cf.tsboot$t0 <- (cf$cf.tsboot$t0)^n
cf$tsboot.se <- apply(cf$cf.tsboot$t, MARGIN = 2L, FUN = cf$error_fn)
cf$cf0 <- cf$cf.tsboot$t0
}
else cf <- invalidate.samples.cf(cf)
return (cf)
}

#' Assign numeric values n to entries of cf objects
#'
#' Note that no complex arithmetic is used, real and imaginary parts are
#' treated as seperate and indepenent, such that the real part of cf is
#' divided by itself and multiplied with n and similarly for the imaginary part.
#'
#' Note that this is generally only allowed on bootstrap samples and mean values,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't understand the documentation here... what is this supposed to do?

@NikSchlage NikSchlage Sep 14, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the FHT ratio function fht_ratio.cf() I calculate the prefactor z/sqrt(z^2 - 1), i.e. "pre <- z / pow.cf(z * z - num.cf(z), n=0.5)". In this, z is a cf object and consequently z * z is also a cf object, because the objects are multiplied element by element. This means that you cannot simply subtract a numeric value. Therefore, I wrote the function num.cf(), which assigns a numeric value to each entry of the passed cf object, in this case 1, since "num.cf <- function(cf, n=1.)". The result is a cf object with the same dimension as z * z that can be subtracted. So here the value 1 is always subtracted. I achieve the assignment of a numeric value n to all entries via cf$cf <- n * (cf$cf/cf$cf) or cf$icf <- n * (cf$icf/cf$icf). This is what I meant with "the real part of cf is divided by itself and multiplied with n and similarly for the imaginary part.".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I have rewritten my documentation again and hope that it is now more understandable.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I remove the check "if( has_icf(cf) )" also in the functions num.cf()? Just like in pow.cf() don't see that it is needed.

#' although it makes sense in some exeptional circumstances. Don't use this
#' function unless you're certain that you should!
#'
#' @param cf `cf_orig` object.
#' @param n Numeric.
#'
#' @return
#' The value is
#' \deqn{n*cf/cf \,.}
#' @export
num.cf <- function(cf, n=1.) {
stopifnot(inherits(cf, 'cf_meta'))
if(inherits(cf, 'cf_orig')) {
cf$cf <- n*(cf$cf/cf$cf)

if( has_icf(cf) ){
stopifnot(has_icf(cf))
cf$icf <- n*(cf$icf/cf$icf)
}
}

if(inherits(cf, 'cf_boot')) {
cf$cf.tsboot$t <- n*(cf$cf.tsboot$t/cf$cf.tsboot$t)
cf$cf.tsboot$t0 <- n*(cf$cf.tsboot$t0/cf$cf.tsboot$t0)
cf$tsboot.se <- apply(cf$cf.tsboot$t, MARGIN = 2L, FUN = cf$error_fn)
cf$cf0 <- cf$cf.tsboot$t0
}
else cf <- invalidate.samples.cf(cf)
return (cf)
}

#' FHT ratio
#'
#' @description
#' Computes Feynman-Hellmann theorem (FHT) ratio for given

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a formula might help

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is done.

#' 2-point and 3-point cf objects.
#'
#' @param cf2pt `cf_orig` object.
#' @param cf3pt `cf_orig` object.
#' @param tau Numeric.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explain what this is please

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I have added the explanations.

#'
#' @return
#' returns the FHT ratio in form of a cf object.
#'
#' @export
fht_ratio.cf <- function(cf2pt, cf3pt, tau) {
z <- ( shift.cf(cf2pt, tau) + shift.cf(cf2pt, -tau) ) / ( mul.cf(cf2pt, 2) )
pre <- z / pow.cf(z*z - num.cf(z), n=0.5)

r <- ( (shift.cf(cf3pt, tau) + shift.cf(cf3pt, -tau)) / (shift.cf(cf2pt, tau) + shift.cf(cf2pt, -tau)) - cf3pt/cf2pt )
res <- mul.cf( pre, (1/tau) ) * r

return(res)
}



#' extract one single correlator object as \code{cf} object from a large
Expand Down