--- title: "Mathematical Description of Methods in `dfddm`" author: "Kendal Foster and Henrik Singmann" date: '`r format(Sys.Date(), "%B %d, %Y")`' bibliography: references.bib output: rmarkdown::html_vignette: css: stile.css toc: false vignette: > %\VignetteIndexEntry{Mathematical Description of Methods in `dfddm`} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r setup, include=FALSE} knitr::opts_chunk$set( collapse = TRUE, error = TRUE, comment = "#>" ) ```
This method is often viewed as the most inefficient of the available options in the literature; however, this method proves to be extremely efficient in particular areas of the parameter space (typically for large $t'$). To implement this method in `dfddm()` (and completely excluding the small-time methods), the user must set the parameter `switch_mech = "large"` in the function call; in this case, the other parameters are ignored.
## Small-Time {#dens-st} The small-time approximations, Equations \(\eqref{eq:con-s}\) and \(\eqref{eq:var-s}\), also contain an infinite sum, but this sum runs over all of the integers – from negative infinity to positive infinity. Given this infinite nature in both directions, it is impossible to rigorously define the number of terms required to achieve the $\epsilon$-accuracy because we don't know where to start counting the terms. To solve this issue, we rearrange the terms in the sum into the sequence $\left\{ b_0, b_{-1}, b_1, \dots, b_{-j}, b_j, b_{-(j+1)}, b_{j+1}, \dots \right\}$; this allows us not only to count the terms in a sensible manner but also to define $k_s$ as the index of the sequence where the truncation should occur. Then we can write the truncated version of the sum: \begin{equation} \label{eq:ks} \sum_{j = -\left\lfloor\frac{k_s}{2}\right\rfloor}^{\left\lfloor\frac{k_s}{2}\right\rfloor} (w + 2j) \exp{ \left( -\frac{a^2}{2t} \left( w + 2j \right)^2 \right)}. \nonumber \end{equation} To choose the small-time methods when using `dfddm()` (and completely excluding the large-time method), set the optional parameter `switch_mech = "small"` in the function call. You can also set the optional control parameter `summation_small = "2017"` or `summation_small = "2014"`, but it is recommended to ignore this parameter so it retains its default value of "2017" that evaluates slightly faster than its counterpart. This parameter controls the style of summation used in the small-time approximation, and more details on the differences between these two styles can be found in the paper accompanying `fddm`. The final control parameter, `n_terms_small`, will be discussed in the following three subsections.To use this method, set `switch_mech = "small"` and `n_terms_small = "Navarro"` in the function call. The parameter `summation_small` should be ignored so that it retains its default value to obtain the best performance.
### Gondan, Blurton, Kesselmeier {#dens-st-gon} After @navarro2009fast published their paper, @gondan2014even introduced another method for calculating the required number of terms in the truncated small-time summation. It is important to note, however, that @gondan2014even provided the number of required _pairs_ of terms in the $S_{14}$ summation style, and not the number of required _individual_ terms. As we want the number of _individual_ terms, we adapt their formula and define it given a desired precision $\epsilon$: \begin{equation} \label{eq:ks-Gon} \begin{aligned} k_s^{\text{Gon}} \left( t', w, \epsilon \right) &= \left\lceil \max \left\{ \tfrac{1}{2} \left( \sqrt{2t'} - w \right), \tfrac{1}{2} \left( \sqrt{-t' (u_\epsilon - \sqrt{-2 u_\epsilon -2})} - w \right) \right\} \right\rceil,\\ u_\epsilon &= \min \left\{ -1, \log(2 \pi t'^2 \epsilon^2) \right\}. \end{aligned} \tag{S.2} \end{equation}To use this method, set `switch_mech = "small"` and `n_terms_small = "Gondan"` in the function call. The parameter `summation_small` should be ignored so that it retains its default value to obtain the best performance.
### Stop When Small Enough (SWSE) {#dens-st-swse} If we consider the terms of the infinite sum as the sequence defined above, the series alternates in sign $(+, -, +, \dots)$; moreover, the series eventually decreases monotonically (in absolute value) due to the exponential term. Combining and exploiting these two mathematical properties has been the cornerstone of the previous approximations, but we will instead truncate the sum using a method suggested by @gondan2014even. This method does not pre-calculate the number of terms required to achieve the given error tolerance. Instead, the general idea of this method is to take full advantage of the alternating and decreasing nature of the terms in the infinite sum by applying a handy theorem (commonly known as the alternating series test) to place an upper bound on the truncation error after including so many terms. It has been proven that this upper bound is in fact the absolute value of the next term in the sequence, thus we can truncate the infinite sum once one of its terms (in absolute value) is less than the desired error tolerance, $\epsilon$. Hence we do not consider the number of terms in the sum, rather just that the terms in the summation will eventually be small enough. The validity of this method is proven in the paper that accompanies the `fddm` package.To use this method, set `swich_mech = "small"` and `n_terms_small = "SWSE"` in the function call. The parameter `summation_small` should be ignored so that it retains its default value to obtain the best performance.
To use this method, set `switch_mech = "terms"` and `n_terms_small = "Navarro"` in the function call. The parameter `summation_small` should be ignored so that it retains its default value to obtain the best performance.
### Gondan Small & Navarro Large {#dens-ct-gon} This combination of methods has not been explored in the literature before, but it works very similarly to the Navarro-Navarro combination above. The only difference is that we use the @gondan2014even approximation for the small-time instead of the one provided by @navarro2009fast. Since $k_s^\text{Gon} \leq k_s^\text{Nav}$, this method should never be less efficient than the previous combined time scale method. \begin{equation} \label{eq:kc-Gon} k_c^{\text{Gon}} \left( t', w, \epsilon \right) = \min \left\{ k_s^{\text{Gon}}, k_l^{\text{Nav}} \right\}. \tag{B.2} \end{equation}To use this method, set `switch_mech = "terms"` and `n_terms_small = "Gondan"` in the function call. The parameter `summation_small` should be ignored so that it retains its default value to obtain the best performance.
### Stop When Small Enough (SWSE) Small & Navarro Large {#dens-ct-swse} The SWSE approximation to the small-time density function differs from the Navarro or Gondan approximations in that it does not pre-calculate $k_s$, the number of terms in the infinite sum that are required to achieve the desired precision; instead, the infinite sum is truncated when the individual terms of the sum become "small enough." This method of truncating the infinite sum poses a problem of how to incorporate this method with the Navarro large-time approximation that relies on pre-calculating $k_\ell^{\text{Nav}}$. We will introduce two heuristics for determining when to use the small-time approximation or the large-time approximation. Both heuristics will use a fourth parameter called `switch_thresh`, but each heuristic will use the new parameter in a slightly different way. The validity of these two methods is proven in the paper that accompanies the `fddm` package. Note that in this paper, the parameter `max_terms_large` is labelled $\delta$.To use this method, set `switch_mech = "terms_large"`. The user may wish to specify a particular threshold (measured in the required number of terms for the truncated sum) for switching between the small-time and large-time approximations by setting the parameter `switch_thresh` (i.e., `switch_thresh = 1`). The parameter `summation_small` should be ignored so that it retains its default value to obtain the best performance.
##### Second Heuristic: Effective Response Time The second heuristic avoids all comparison with $k_\ell^{\text{Nav}}$ as it simply considers the effective response time, $t' := \tfrac{t}{a^2}$, to be the indicator of a small or large response time. $t'$ is compared to a new parameter `switch_thresh` so that if $t'$ $>$ `switch_thresh`, then the Navarro large-time approximation is used; otherwise, the SWSE small-time approximation is used. The user can alter the behavior of this method by setting the optional parameter `switch_thresh` to any non-negative real number; the default value for this parameter when using this method is $0.8$.Since this is the default implementation, all four of the optional parameters (`switch_mech`, `switch_thresh`, `n_terms_small`, and `summation_small`) can be ignored. The user may wish to specify a particular threshold (measured in seconds) for switching between the small-time and large-time approximations by setting the parameter `switch_thresh` (i.e., `switch_thresh = 0.8`). We recommend ignoring the parameter `summation_small` so that it retains its default value and achieves optimal performance. Note that the parameter `n_terms_small` is ignored because the only option is "SWSE".