-
Notifications
You must be signed in to change notification settings - Fork 13
Cf adds #309
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
base: master
Are you sure you want to change the base?
Cf adds #309
Changes from 3 commits
cfa0e9d
383a481
48bb66d
d33b3d9
f59cfea
209a1eb
4fc2ceb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
||
| if( has_icf(cf) ){ | ||
| stopifnot(has_icf(cf)) | ||
|
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, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.".
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a formula might help
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. explain what this is please
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.