enhanceFunctionWithBoundaries | R Documentation |
The method takes a function as well as values for lower and upper boundaries and returns a modified function. The modified function returns the value of the original function when the parameters are within boundaries and the penalty value otherwise.
enhanceFunctionWithBoundaries(
fun,
l_bound,
u_bound,
penalty_value = Inf,
boundary_fun = NULL,
param_pos = 1,
...
)
fun |
function to be modified |
l_bound |
vector with lower boundary values |
u_bound |
vector with upper boundary values |
penalty_value |
value if parameter outside boundaries |
boundary_fun |
optional function for complex boundary conditions |
param_pos |
argument position of the parameter |
... |
arguments passed to original function |
Optionally an own function can be supplied to calculate whether the parameter is valid. The boundary function must take 3 arguments: parameter, lower boundary and upper boundary and must return TRUE or FALSE.
A main use case of this method are optimisation / calibration tasks. If the optimisation method and the function to optimise are both ignorant to boundaries one can turn the function into a boundary sensitive one.
a modified function that considers boundaries
sqrt_bd <- enhanceFunctionWithBoundaries(sqrt, 0, 10)
sqrt_bd(-1)
sqrt_bd(1)
sqrt_bd(11)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.