aab_env.Rd
Functions available to any gadget3 model
g3_env
is the top-level environment that any gadget3 model uses,
populated with utility functions.
NB: Several functions have _vec
variants.
Due to TMB limitations these should be used when you have a vector not scalar input.
TMB's ADREPORT
function. See sdreport documentation
C++ compatible equivalent to as.integer
R as.numeric
or TMB asDouble
C++/R function that ensures expression is true, or stops model.
assert_msg(x > 0, "x must be positive")
Adds small value to input to ensure output is never zero
Apply matrix transformation tf to vector vec, return resultant vector.
g3_matrix_vec(tf, vec)
Vector equivalent of lgamma
TMB's logspace_add
, essentially a differentiable version of pmax
.
Divide vector a by it's sum, i.e. so it now sums to 1
Return first non-null argument. NB: No C++ implementation.
Vector equivalent of ^
Utility to pretty-print array ar
Sum orig_vec & new_vec according to ratio of orig_amount & new_amount
TMB's REPORT
function.
Equivalent of RCpp REprintf
Equivalent of RCpp Rprintf
## avoid_zero / avoid_zero_vec
g3_eval(quote( c( avoid_zero(0), avoid_zero(10) ) ))
#> [1] 6.931472e-04 1.000000e+01
g3_eval(quote( avoid_zero_vec(0:5) ))
#> [1] 0.0006931472 1.0000000000 2.0000000000 3.0000000000 4.0000000000
#> [6] 5.0000000000
## bounded / bounded_vec
curve(g3_eval(quote( bounded(x, 100, 200) ), x = x), -100, 100)
## logspace_add
curve(g3_eval(quote( logspace_add(x, 10) ), x = x), 0, 40)
## normalize_vec
g3_eval(quote( normalize_vec(c( 4, 4, 8, 2 )) ))
#> [1] 0.2222222 0.2222222 0.4444444 0.1111111