Debian Codegraph @

man/expand-methods.Rd

raw
1 \name{expand}
2
3 \alias{expand}
4 \alias{expand,Intervals_virtual-method}
5
6 \alias{contract}
7 \alias{contract,Intervals_virtual-method}
8
9 \title{Expand or contract intervals}
10
11 \description{
12 It is often useful to shrink or grow each interval in a set of
13 intervals: to smooth over small, uninteresting gaps, or to address
14 possible imprecision resulting from floating point arithmetic. The
15 \code{expand} and \code{contract} methods implement this, using either
16 absolute or relative difference.
17 }
18
19 \usage{
20 \S4method{expand}{Intervals_virtual}(x, delta = 0, type = c("absolute", "relative"))
21
22 \S4method{contract}{Intervals_virtual}(x, delta = 0, type = c("absolute", "relative"))
23 }
24
25
26 \arguments{
27
28 \item{x}{ An \code{"Intervals"} or \code{"Intervals_full"} object.}
29
30 \item{delta}{
31 A non-negative adjustement value. A vector is permitted,
32 and its entries will be recycled if necessary.
33 }
34
35 \item{type}{
36 Should adjustment be based on relative or absolute difference. When
37 \code{type == "relative"} intervals are expanded/contracted to
38 include/exclude points for which a relative difference with respect
39 to the nominal value is less than or equal to \code{delta}. (See the
40 note below.) When \code{type == "absolute"}, absolute rather than
41 relative difference is used, i.e., all intervals are expanded or
42 contracted by the same amount.
43 }
44
45 }
46
47 \value{
48 A single object of appropriate class, with endpoint positions adjusted
49 as requested. Expansion returns an object with the same dimension as
50 \code{x}; contraction may lead to the elimination of now-empty rows.
51 }
52
53 \note{
54 Here, the relative difference between \emph{x} and \emph{y} is
55 |\emph{x} - \emph{y}|/max(|\emph{x}|, |\emph{y}|).
56 }
57
58 \examples{
59 # Using adjustment to remove small gaps
60
61 x <- Intervals( c(1,10,100,8,50,200), type = "Z" )
62 close_intervals( contract( reduce( expand(x, 1) ), 1 ) )
63
64 # Finding points for which, as a result of possible floating point
65 # error, intersection may be ambiguous. Whether y1 intersects y2[2,]
66 # depends on precision.
67
68 delta <- .Machine$double.eps^0.5
69 y1 <- Intervals( c( .5, 1 - delta / 2 ) )
70 y2 <- Intervals( c( .25, 1, .75, 2 ) )
71
72 # Nominal
73
74 interval_intersection( y1, y2 )
75
76 # Inner limit
77
78 inner <- interval_intersection(
79 contract( y1, delta, "relative" ),
80 contract( y2, delta, "relative" )
81 )
82
83 # Outer limit
84
85 outer <- interval_intersection(
86 expand( y1, delta, "relative" ),
87 expand( y2, delta, "relative" )
88 )
89
90 # The ambiguous set, corresponding to points which may or may not be in
91 # the intersection -- depending on numerical values for endpoints
92 # which are, with respect to relative difference, indistinguishable from
93 # the nominal values.
94
95 interval_difference( outer, inner )
96 }