env_dif: g3 env: differentiable functions

env_difR Documentation

g3 env: differentiable functions

Description

Differentiable helper functions available to any gadget3 model

Details

These functions are part of g3_env is the top-level environment that any gadget3 model uses.

dif_pmax

dif_pmax(a, b, scale)

Returns the maximum of a & b. If a is a vector/array, then all members of a are compared against b. If b is also a vector, then all members of a are compared against the matching member of b (repeating b if necessary).

scale influences the sharpness of inflection points, should be about 1e5, depending on ranges of input values.

dif_pmin

dif_pmin(a, b, scale)

Returns the minimum of a & b, otherwise works like dif_pmax.

scale influences the sharpness of inflection points, should be about 1e5, depending on ranges of input values.

dif_pminmax

dif_pminmax(a, lower, upper, scale)

Returns values of a bounded between lower & upper.

scale influences the sharpness of inflection points at lower & upper, should be about 1e5, depending on ranges of input values.

Examples

## dif_pmax
g3_eval(quote( dif_pmax(1:10, 5, 1e5) ))
g3_eval(quote( dif_pmax(1:10, c(4, 7), 1e5) ))
g3_eval(quote( dif_pmax(array(1:9, dim = c(3,3)), c(3,6,8), 1e5) ))

## dif_pmin
g3_eval(quote( dif_pmin(1:10, 5, 1e5) ))
g3_eval(quote( dif_pmin(1:10, c(4, 7), 1e5) ))

## dif_pminmax
g3_eval(quote( dif_pminmax(1:10, 3, 6, 1e5) ))


lentinj/gadget3 documentation built on June 12, 2025, 5:46 a.m.