Class RadicalInverse
- java.lang.Object
-
- umontreal.iro.lecuyer.hups.RadicalInverse
-
public class RadicalInverse extends java.lang.ObjectThis class implements basic methods for working with radical inverses of integers in an arbitrary basis b. These methods are used in classes that implement point sets and sequences based on the van der Corput sequence (the Hammersley nets and the Halton sequence, for example).We recall that for a k-digit integer i whose digital b-ary expansion is
i = a0 + a1b + ... + ak-1bk-1,the radical inverse in base b isψb(i) = a0b-1 + a1b-2 + ... + ak-1b-k.The van der Corput sequence in base b is the sequence ψb(0), ψb(1), ψb(2),...Note that ψb(i) cannot always be represented exactly as a floating-point number on the computer (e.g., if b is not a power of two). For an exact representation, one can use the integer
bkψb(i) = ak-1 + ... + a1bk-2 + a0bk-1,which we called the integer radical inverse representation. This representation is simply a mirror image of the digits of the usual b-ary representation of i.It is common practice to permute locally the values of the van der Corput sequence. One way of doing this is to apply a permutation to the digits of i before computing ψb(i). That is, for a permutation π of the digits {0,..., b - 1},
ψb(i) = ∑r=0k-1arb-r-1is replaced by∑r=0k-1π(ar)b-r-1.Applying such a permutation only changes the order in which the values of ψb(i) are enumerated. For every integer k, the first bk values that are enumerated remain the same (they are the values of ψb(i) for i = 0,..., bk - 1), but they are enumerated in a different order. Often, different permutations π will be applied for different coordinates of a point set.The permutation π can be deterministic or random. One (deterministic) possibility implemented here is the Faure permutation σb of {0,..., b - 1} defined as follows. For b = 2, take σ = I, the identical permutation. For even b = 2c > 2, take
σ[i] = 2τ[i] i = 0, 1,…, c - 1 σ[i + c] = 2τ[i] + 1 i = 0, 1,…, c - 1
where τ[i] is the Faure permutation for base c. For odd b = 2c + 1, take
σ[c] = c σ[i] = τ[i], if 0 <= τ[i] < c σ[i] = τ[i] + 1, if c <= τ[i] < 2c
for 0 <= i < c, and take
σ[i] = τ[i - 1], if 0 <= τ[i - 1] < c σ[i] = τ[i - 1] + 1, if c <= τ[i - 1] < 2c
for c < i <= 2c, and where τ[i] is the Faure permutation for base c. The Faure permutations give very small discrepancies (amongst the best known today) for small bases.
-
-
Constructor Summary
Constructors Constructor and Description RadicalInverse(int b, double x0)Initializes the base of this object to b and its first value of x to x0.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description static voidgetFaurePermutation(int b, int[] pi)Computes the Faure permutation σb of the set {0,…, b - 1} and puts it in array pi.static int[]getPrimes(int n)Provides an elementary method for obtaining the first n prime numbers larger than 1.static intintegerRadicalInverse(int b, int i)Computes the integer radical inverse of i in base b, equal to bkψb(i) if i has k b-ary digits.doublenextRadicalInverse()A fast method that incrementally computes the radical inverse xi+1 in base b from xi = ψb(i), using addition with rigthward carry as described in Wang and Hickernell.static doublenextRadicalInverse(double invb, double x)A fast method that incrementally computes the radical inverse xi+1 in base b from xi = x = ψb(i), using addition with rigthward carry.static intnextRadicalInverseDigits(int b, int k, int[] idigits)Given the k digits of the integer radical inverse of i in bdigits, in base b, this method replaces them by the digits of the integer radical inverse of i + 1 and returns their number.static doublepermutedRadicalInverse(int b, int[] pi, int i)Computes the radical inverse of i in base b, where the digits are permuted using the permutation π.static doubleradicalInverse(int b, long i)Computes the radical inverse of i in base b.static voidreverseDigits(int k, int[] bdigits, int[] idigits)Given the k b-ary digits of i in bdigits, returns the k digits of the integer radical inverse of i in idigits.
-
-
-
Constructor Detail
-
RadicalInverse
public RadicalInverse(int b, double x0)Initializes the base of this object to b and its first value of x to x0.- Parameters:
b- Basex0- Initial value of x
-
-
Method Detail
-
getPrimes
public static int[] getPrimes(int n)
Provides an elementary method for obtaining the first n prime numbers larger than 1. Creates and returns an array that contains these numbers. This is useful for determining the prime bases for the different coordinates of the Halton sequence and Hammersley nets.- Parameters:
n- number of prime numbers to return- Returns:
- an array with the first n prime numbers
-
radicalInverse
public static double radicalInverse(int b, long i)Computes the radical inverse of i in base b. If i = ∑r=0k-1arbr, the method computes and returnsx = ∑r=0k-1arb-r-1.- Parameters:
b- base used for the operationi- the value for which the radical inverse will be computed- Returns:
- the radical inverse of i in base b
-
nextRadicalInverse
public static double nextRadicalInverse(double invb, double x)A fast method that incrementally computes the radical inverse xi+1 in base b from xi = x = ψb(i), using addition with rigthward carry. The parameter invb is equal to 1/b. Using long incremental streams (i.e., calling this method several times in a row) cause increasing inaccuracy in x. Thus the user should recompute the radical inverse directly by callingradicalInverseevery once in a while (i.e. in every few thousand calls).- Parameters:
invb- 1/b where b is the basex- the inverse xi- Returns:
- the radical inverse xi+1
-
nextRadicalInverse
public double nextRadicalInverse()
A fast method that incrementally computes the radical inverse xi+1 in base b from xi = ψb(i), using addition with rigthward carry as described in Wang and Hickernell. Since using long incremental streams (i.e., calling this method several times in a row) cause increasing inaccuracy in x, the method recomputes the radical inverse directly from i by callingradicalInverseonce in every 1000 calls.- Returns:
- the radical inverse xi+1
-
reverseDigits
public static void reverseDigits(int k, int[] bdigits, int[] idigits)Given the k b-ary digits of i in bdigits, returns the k digits of the integer radical inverse of i in idigits. This simply reverses the order of the digits.- Parameters:
k- number of digits in arraysbdigits- digits in original orderidigits- digits in reverse order
-
integerRadicalInverse
public static int integerRadicalInverse(int b, int i)Computes the integer radical inverse of i in base b, equal to bkψb(i) if i has k b-ary digits.- Parameters:
b- base used for the operationi- the value for which the integer radical inverse will be computed- Returns:
- the integer radical inverse of i in base b
-
nextRadicalInverseDigits
public static int nextRadicalInverseDigits(int b, int k, int[] idigits)Given the k digits of the integer radical inverse of i in bdigits, in base b, this method replaces them by the digits of the integer radical inverse of i + 1 and returns their number. The array must be large enough to hold this new number of digits.- Parameters:
b- basek- initial number of digits in arraysidigits- digits of integer radical inverse- Returns:
- new number of digits in arrays
-
getFaurePermutation
public static void getFaurePermutation(int b, int[] pi)Computes the Faure permutation σb of the set {0,…, b - 1} and puts it in array pi. See the description in the introduction above.- Parameters:
b- the basepi- an array of size at least b, to be filled with the permutation
-
permutedRadicalInverse
public static double permutedRadicalInverse(int b, int[] pi, int i)Computes the radical inverse of i in base b, where the digits are permuted using the permutation π. If i = ∑r=0k-1arbr, the method will compute and returnx = ∑r=0k-1π[ar]b-r-1.- Parameters:
b- base b used for the operationpi- an array of length at least b containing the permutation used during the computationi- the value for which the radical inverse will be computed- Returns:
- the radical inverse of i in base b
-
-
DMelt 3.0 © DataMelt by jWork.ORG