fun_approx {rbbnp} | R Documentation |
Approximation Function for Intensive Calculations
Description
This function provides a lookup-based approximation for calculations that are computationally intensive. Once computed, it stores the results in an environment and uses linear interpolation for new data points to speed up subsequent computations.
Usage
fun_approx(u, u_lb = -100, u_ub = 100, resol = 1000, fun = W_kernel)
Arguments
u |
A vector of values where the function should be evaluated. |
u_lb |
Lower bound for the precomputed range. Defaults to -10. |
u_ub |
Upper bound for the precomputed range. Defaults to 10. |
resol |
The resolution or number of sample points in the precomputed range. Defaults to 1000. |
fun |
A function for which the approximation is computed. Defaults to the |
Details
The fun_approx
function works by initially creating a lookup table of function values based on
the range specified by u_lb
and u_ub
and the resolution resol
. This precomputation only happens once
for a given set of parameters (u_lb
, u_ub
, resol
, and fun
). Subsequent calls to fun_approx
with the
same parameters use the lookup table to find the closest precomputed points to the requested u
values
and then return an interpolated result.
Linear interpolation is used between the two closest precomputed points in the lookup table. This ensures a smooth approximation for values in between sample points.
This function is especially useful for computationally intensive functions where recalculating
function values is expensive or time-consuming. By using a combination of precomputation and
interpolation, fun_approx
provides a balance between accuracy and speed.
Value
A vector of approximated function values corresponding to u
.