intervals (version 0.15.1)

expand: Expand or contract intervals

Description

It is often useful to shrink or grow each interval in a set of intervals: to smooth over small, uninteresting gaps, or to address possible imprecision resulting from floating point arithmetic. The expand and contract methods implement this, using either absolute or relative difference.

Usage

# S4 method for Intervals_virtual
expand(x, delta = 0, type = c("absolute", "relative"))

# S4 method for Intervals_virtual contract(x, delta = 0, type = c("absolute", "relative"))

Arguments

x

An "Intervals" or "Intervals_full" object.

delta

A non-negative adjustement value. A vector is permitted, and its entries will be recycled if necessary.

type

Should adjustment be based on relative or absolute difference. When type == "relative" intervals are expanded/contracted to include/exclude points for which a relative difference with respect to the nominal value is less than or equal to delta. (See the note below.) When type == "absolute", absolute rather than relative difference is used, i.e., all intervals are expanded or contracted by the same amount.

Value

A single object of appropriate class, with endpoint positions adjusted as requested. Expansion returns an object with the same dimension as x; contraction may lead to the elimination of now-empty rows.

Examples

Run this code
# NOT RUN {
# Using adjustment to remove small gaps

x <- Intervals( c(1,10,100,8,50,200), type = "Z" )
close_intervals( contract( reduce( expand(x, 1) ), 1 ) )

# Finding points for which, as a result of possible floating point
# error, intersection may be ambiguous. Whether y1 intersects y2[2,]
# depends on precision.

delta <- .Machine$double.eps^0.5
y1 <- Intervals( c( .5, 1 - delta / 2 ) )
y2 <- Intervals( c( .25, 1, .75, 2 ) )

# Nominal 

interval_intersection( y1, y2 )

# Inner limit

inner <- interval_intersection(
                               contract( y1, delta, "relative" ),
                               contract( y2, delta, "relative" )
                               )

# Outer limit

outer <- interval_intersection(
                               expand( y1, delta, "relative" ),
                               expand( y2, delta, "relative" )
                               )

# The ambiguous set, corresponding to points which may or may not be in
# the intersection -- depending on numerical values for endpoints
# which are, with respect to relative difference, indistinguishable from
# the nominal values.

interval_difference( outer, inner )
# }

Run the code above in your browser using DataLab