Learn R Programming

vws (version 0.3.0)

rect: Rectangular transformation

Description

A transformation from unconstrained \(\mathbb{R}^d\) to a rectangle in \(\mathbb{R}^d\), and its inverse transformation.

Usage

rect(z, a, b)

inv_rect(x, a, b)

Value

A vector of length \(d\).

Arguments

z

A point in the rectangle \([a_1,b_1] \times \cdots \times [a_d,b_d]\).

a

A vector \((a_1, \ldots, a_d)\), Elements may be -Inf.

b

A vector \((b_1, \ldots, b_d)\), Elements may be +Inf.

x

A point in \(\mathbb{R}^{d}\).

Examples

Run this code
n = 20
x = seq(-5, 5, length.out = n)

# Transform x to the interval [-1, 1]
a = rep(-1, n)
b = rep(+1, n)
z = inv_rect(x, a, b)
print(z)
xx = rect(z, a, b)
stopifnot(all(abs(x - xx) < 1e-8))

# Transform x to the interval [-Inf, 1]
a = rep(-Inf, n)
b = rep(+1, n)
z = inv_rect(x, a, b)
print(z)
xx = rect(z, a, b)
stopifnot(all(abs(x - xx) < 1e-8))

# Transform x to the interval [-1, Inf]
a = rep(-1, n)
b = rep(+Inf, n)
z = inv_rect(x, a, b)
print(z)
xx = rect(z, a, b)
stopifnot(all(abs(x - xx) < 1e-8))

# Transform x to the interval [-Inf, Inf]
a = rep(-Inf, n)
b = rep(+Inf, n)
z = inv_rect(x, a, b)
print(z)
xx = rect(z, a, b)
stopifnot(all(abs(x - xx) < 1e-8))

Run the code above in your browser using DataLab