enhanceFunctionWithBoundaries: Modifies function to return a penalty value for parameters...

View source: R/optim_helper.R

enhanceFunctionWithBoundariesR Documentation

Modifies function to return a penalty value for parameters outside boundaries

Description

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.

Usage

enhanceFunctionWithBoundaries(
  fun,
  l_bound,
  u_bound,
  penalty_value = Inf,
  boundary_fun = NULL,
  param_pos = 1,
  ...
)

Arguments

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

Details

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.

Value

a modified function that considers boundaries

Examples

sqrt_bd <- enhanceFunctionWithBoundaries(sqrt, 0, 10)
sqrt_bd(-1)
sqrt_bd(1)
sqrt_bd(11)


simplaceUtil documentation built on Aug. 6, 2024, 3:01 p.m.