50% off: Unlimited data and AI learning.
State of Data and AI Literacy Report 2025

simecol (version 0.9-3)

p.constrain: Transform Data Between Unconstrained and Box-constrained Scale

Description

These functions can be used to transform a vector of data or parameters between unconstrained [-Inf, Inf] and box-constrained representation (interval [lower, upper]).

Usage

p.constrain(p, lower = -Inf, upper = Inf, f = 1)
p.unconstrain(p, lower = -Inf, upper = Inf, f = 1)

Value

vector with transformed (resp. back-transformed) values.

Arguments

p

vector of data (e.g. model parameters),

lower, upper

vectors with lower resp. upper bounds used for transformation,

f

optional scaling factor.

Details

These functions are employed by fitOdeModel ssqOdeModel in order to be able to use the unconstrained optimizers of optim for constrained optimization.

The transformation functions are

p=tan(π/2(2pupperlower)/(upperlower))1/f

and its inverse

p=(upper+lower)/2+(upperlower)arctan(fp)/π.

References

This trick seems to be quite common, but in most cases it is preferred to apply optimizers that can handle constraints internally.

Reichert, T. (1998) AQUASIM 2.0 User Manual. Computer Program for the Identification and Simulation of Aquatic Systems. Swiss Federal Institute for Environmental Science and Technology (EAWAG), CH - 8600 Duebendorf Switzerland, https://www.eawag.ch/de/abteilung/siam/software/.

See Also

fitOdeModel, ssqOdeModel

Examples

Run this code
xx <- seq(-100, 100, 2)
plot(xx, yy<-p.constrain(xx, -20, 45), type="l")
points(p.unconstrain(yy, -20, 45), yy, col="red")

Run the code above in your browser using DataLab