Learn R Programming

propagate (version 1.3-0)

interval: Range of a function over intervals of its input variables

Description

Calculates the range \([\min f, \max f]\) of a model \(f(x_1, \ldots, x_N)\) when each input variable is only known to lie in an interval \([A_i, B_i]\). The function is evaluated on a grid over the box of input intervals ("vertex" or "grid" method), and the grid minimum and maximum are refined by box-constrained optimisation. Unlike naive interval arithmetic, the result is not inflated by the dependency problem.

Usage

interval(df, expr, seq = 10, plot = TRUE, refine = TRUE, maxgrid = 1E6)

# S3 method for interval print(x, ...)

Value

An object of class interval: a vector with the elements lower and upper, and the attributes argmin and argmax (the input values at the extrema) and ngrid (the number of grid points).

Arguments

df

a data frame or matrix with two rows, the lower limits \(A_i\) in the first row and the upper limits \(B_i\) in the second row. Column names must correspond to the variable names in expr; further columns are ignored.

expr

an expression, such as expression(x/y).

seq

the number of grid points per variable from \(A_i\) to \(B_i\) (at least 2, i.e. the interval limits); 0 is added to intervals containing zero.

plot

logical. If TRUE, the grid evaluations are plotted, with the range as blue lines.

refine

logical. If TRUE, the grid minimum and maximum are refined by optim (method "L-BFGS-B", bounded by the input intervals), which finds extrema between grid points.

maxgrid

the maximal number of grid points \(\prod_i n_i\), with \(n_i\) = seq (+1 if 0 is added) the number of grid points of variable \(i\); the grid grows as seq\(^N\) with the number \(N\) of variables.

x

an object of class interval.

...

not used.

Author

Andrej-Nikolai Spiess

Details

Interval arithmetic and the dependency problem. For two intervals \([x_1, x_2]\) and \([y_1, y_2]\), the basic operations \(\circ \in \{+, -, \cdot, /\}\) of interval arithmetic are $$[x_1, x_2] \circ [y_1, y_2] = [\min(x_i \circ y_j), \max(x_i \circ y_j)], \quad i, j \in \{1, 2\}$$ (for division, \(0 \notin [y_1, y_2]\)). Applied operation by operation, this overestimates the range when a variable occurs more than once in an expression, because each occurrence is treated as an independent variable (dependency problem): e.g., \(x - x^2\) with \(x \in [0, 1]\) gives \([0, 1] - [0, 1] = [-1, 1]\), while the true range is \([0, 0.25]\).

Vertex and grid method. interval avoids this by evaluating \(f\) as a whole. With seq = 2, \(f\) is evaluated at the \(2^N\) vertices of the box (all combinations of the interval limits); this gives the exact range if \(f\) is monotone in each variable. If not, the extrema may lie inside the box: a larger seq evaluates \(f\) on a finer grid (seq\(^N\) points, with 0 added to intervals containing zero, e.g. for even powers), and refine = TRUE refines the grid minimum and maximum by bounded optimisation.

Inner approximation. The result is the range of the evaluated points and optimisation results, which can only be narrower than (or equal to) the true range: it is an inner approximation, not a guaranteed enclosure as in rigorous interval arithmetic. For functions with several local extrema, use a finer grid. Grid points where \(f\) is not finite (outside its domain) are ignored with a warning.

References

Interval arithmetic and the dependency problem:
Introduction to Interval Analysis.
Moore RE, Kearfott RB, Cloud MJ.
SIAM, Philadelphia (2009).
tools:::Rd_expr_doi("10.1137/1.9780898717716")

Comparison to Monte Carlo and error propagation:
Interval arithmetic in power flow analysis.
Wang Z, Alvarado FL.
IEEE Transactions on Power Systems (1992), 7: 1341-1349.
tools:::Rd_expr_doi("10.1109/59.207353")

Computer implementation:
Interval arithmetic: From principles to implementation.
Hickey T, Ju Q, Van Emden MH.
Journal of the ACM (2001), 48: 1038-1068.
tools:::Rd_expr_doi("10.1145/502102.502106")

Complete interval arithmetic and its implementation on the computer.
Kulisch UW.
In: Numerical Validation in Current Hardware Architectures. Cuyt A, Kraemer W, Luther W, Markstein P (Eds.). Springer (2009), Lecture Notes in Computer Science 5492: 7-26.
tools:::Rd_expr_doi("10.1007/978-3-642-01591-5")

See Also

propagate, makeDat

Examples

Run this code
## Example 1: even power of an interval containing zero: [0, 1], not [-1, 1].
interval(data.frame(x = c(-1, 1)), expression(x^2))

## Example 2: a nonlinear model, monotone in each variable:
## the vertices (seq = 2) give the exact range.
EXPR2 <- expression(Cf * sqrt((520 * H * P)/(M * (Temp + 460))))
H <- c(64, 65); M <- c(16, 16.2); P <- c(361, 365); Temp <- c(165, 170); Cf <- c(38.4, 38.5)
DAT2 <- makeDat(EXPR2)
interval(DAT2, EXPR2, seq = 2)

## Example 3: body mass index.
EXPR3 <- expression(m/h^2)
m <- c(79.5, 80.5); h <- c(1.795, 1.805)
DAT3 <- makeDat(EXPR3)
interval(DAT3, EXPR3)

## Example 4: minimum inside the interval. For x in [-2, 1], naive interval arithmetic gives
## [0, 4] - [-2, 1] + 1 = [0, 7] (or [-2, 7] if x^2 is computed as x * x);
## the true range is [0.75, 7].
EXPR4 <- expression(x^2 - x + 1)
x <- c(-2, 1)
DAT4 <- makeDat(EXPR4)
interval(DAT4, EXPR4, seq = 2, refine = FALSE)  ## vertices and 0 only: [1, 7]
interval(DAT4, EXPR4, seq = 2)                  ## refined: [0.75, 7]
curve(x^2 - x + 1, -2, 1)

## Example 5: dependency problem. Naive interval arithmetic gives
## [0, 1] - [0, 1] = [-1, 1]; the true range is [0, 0.25].
EXPR5 <- expression(x - x^2)
x <- c(0, 1)
DAT5 <- makeDat(EXPR5)
interval(DAT5, EXPR5, seq = 2, refine = FALSE)  ## vertices only: [0, 0]
interval(DAT5, EXPR5)                           ## [0, 0.25]
curve(x - x^2, 0, 1)

Run the code above in your browser using DataLab