public static void i4_to_halton_sequence(int dim_num, int n, int step, int[] seed, int[] leap, int[] base_, ref double[] r) //****************************************************************************80 // // Purpose: // // I4_TO_HALTON_SEQUENCE computes N elements of a leaped Halton subsequence. // // Discussion: // // The DIM_NUM-dimensional Halton sequence is really DIM_NUM separate // sequences, each generated by a particular base. // // This routine selects elements of a "leaped" subsequence of the // Halton sequence. The subsequence elements are indexed by a // quantity called STEP, which starts at 0. The STEP-th subsequence // element is simply element // // SEED(1:DIM_NUM) + STEP * LEAP(1:DIM_NUM) // // of the original Halton sequence. // // // The data to be computed has two dimensions. // // The number of data items is DIM_NUM * N, where DIM_NUM is the spatial dimension // of each element of the sequence, and N is the number of elements of the sequence. // // The data is stored in a one dimensional array R. The first element of the // sequence is stored in the first DIM_NUM entries of R, followed by the DIM_NUM entries // of the second element, and so on. // // In particular, the J-th element of the sequence is stored in entries // 0+(J-1)*DIM_NUM through (DIM_NUM-1) + (J-1)*DIM_NUM. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 16 July 2004 // // Author: // // John Burkardt // // Reference: // // J H Halton, // On the efficiency of certain quasi-random sequences of points // in evaluating multi-dimensional integrals, // Numerische Mathematik, // Volume 2, 1960, pages 84-90. // // J H Halton and G B Smith, // Algorithm 247: Radical-Inverse Quasi-Random Point Sequence, // Communications of the ACM, // Volume 7, 1964, pages 701-702. // // Ladislav Kocis and William Whiten, // Computational Investigations of Low-Discrepancy Sequences, // ACM Transactions on Mathematical Software, // Volume 23, Number 2, 1997, pages 266-294. // // Parameters: // // Input, int DIM_NUM, the spatial dimension. // // Input, int N, the number of elements of the sequence. // // Input, int STEP, the index of the subsequence element. // 0 <= STEP is required // // Input, int SEED[DIM_NUM], the Halton sequence index corresponding // to STEP = 0. // // Input, int LEAP[DIM_NUM], the succesive jumps in the Halton sequence. // // Input, int BASE[DIM_NUM], the Halton bases. // // Output, double R[DIM_NUM*N], the next N elements of the // leaped Halton subsequence, beginning with element STEP. // { int i; // // Check the input. // if (!Halham.halham_dim_num_check(dim_num)) { return; } if (!Halham.halham_n_check(n)) { return; } if (!Halham.halham_step_check(step)) { return; } if (!Halham.halham_seed_check(dim_num, seed)) { return; } if (!Halham.halham_leap_check(dim_num, leap)) { return; } if (!halton_base_check(dim_num, base_)) { return; } // // Calculate the data. // int[] seed2 = new int[n]; for (i = 0; i < dim_num; i++) { int j; for (j = 0; j < n; j++) { seed2[j] = seed[i] + (step + j) * leap[i]; } for (j = 0; j < n; j++) { r[i + j * dim_num] = 0.0; } for (j = 0; j < n; j++) { double base_inv = 1.0 / base_[i]; while (seed2[j] != 0) { int digit = seed2[j] % base_[i]; r[i + j * dim_num] += digit * base_inv; base_inv /= base_[i]; seed2[j] /= base_[i]; } } } }
public static void i4_to_hammersley_sequence(int dim_num, int n, int step, int[] seed, int[] leap, int[] base_, ref double[] r) //****************************************************************************80 // // Purpose: // // I4_TO_HAMMERSLEY_SEQUENCE computes N elements of a leaped Hammersley subsequence. // // Discussion: // // The DIM_NUM-dimensional Hammersley sequence is really DIM_NUM separate // sequences, each generated by a particular base. If the base is // greater than 1, a standard 1-dimensional // van der Corput sequence is generated. But if the base is // negative, this is a signal that the much simpler sequence J/(-BASE) // is to be generated. For the standard Hammersley sequence, the // first spatial coordinate uses a base of (-N), and subsequent // coordinates use bases of successive primes (2, 3, 5, 7, 11, ...). // This program allows the user to specify any combination of bases, // included nonprimes and repeated values. // // This routine selects elements of a "leaped" subsequence of the // Hammersley sequence. The subsequence elements are indexed by a // quantity called STEP, which starts at 0. The STEP-th subsequence // element is simply element // // SEED(1:DIM_NUM) + STEP * LEAP(1:DIM_NUM) // // of the original Hammersley sequence. // // // The data to be computed has two dimensions. // // The number of data items is DIM_NUM * N, where DIM_NUM is the spatial dimension // of each element of the sequence, and N is the number of elements of the sequence. // // The data is stored in a one dimensional array R. The first element of the // sequence is stored in the first DIM_NUM entries of R, followed by the DIM_NUM entries // of the second element, and so on. // // In particular, the J-th element of the sequence is stored in entries // 0+(J-1)*DIM_NUM through (DIM_NUM-1) + (J-1)*DIM_NUM. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 30 September 2004 // // Author: // // John Burkardt // // Reference: // // J M Hammersley, // Monte Carlo methods for solving multivariable problems, // Proceedings of the New York Academy of Science, // Volume 86, 1960, pages 844-874. // // Ladislav Kocis and William Whiten, // Computational Investigations of Low-Discrepancy Sequences, // ACM Transactions on Mathematical Software, // Volume 23, Number 2, 1997, pages 266-294. // // Parameters: // // Input, int DIM_NUM, the spatial dimension. // // Input, int N, the number of elements of the sequence. // // Input, int STEP, the index of the subsequence element. // 0 <= STEP is required // // Input, int SEED[DIM_NUM], the Hammersley sequence index corresponding // to STEP = 0. // // Input, int LEAP[DIM_NUM], the succesive jumps in the Hammersley sequence. // // Input, int BASE[DIM_NUM], the Hammersley bases. // // Output, double R[DIM_NUM*N], the next N elements of the // leaped Hammersley subsequence, beginning with element STEP. // { const double FIDDLE = 0.0; int i; // // Check the input. // if (!Halham.halham_dim_num_check(dim_num)) { return; } if (!Halham.halham_n_check(n)) { return; } if (!Halham.halham_step_check(step)) { return; } if (!Halham.halham_seed_check(dim_num, seed)) { return; } if (!Halham.halham_leap_check(dim_num, leap)) { return; } if (!hammersley_base_check(dim_num, base_)) { return; } // // Calculate the data. // int[] seed2 = new int[n]; for (i = 0; i < dim_num; i++) { int j; switch (base_[i]) { case > 1: { for (j = 0; j < n; j++) { seed2[j] = seed[i] + (step + j) * leap[i]; } for (j = 0; j < n; j++) { r[i + j * dim_num] = 0.0; } for (j = 0; j < n; j++) { double base_inv = 1.0 / base_[i]; while (seed2[j] != 0) { int digit = seed2[j] % base_[i]; r[i + j * dim_num] += digit * base_inv; base_inv /= base_[i]; seed2[j] /= base_[i]; } } break; } // default: { for (j = 0; j < n; j++) { int temp = (seed[i] + (step + j) * leap[i]) % -base_[i]; r[i + j * dim_num] = (temp + FIDDLE) / -base_[i]; } break; } } } }
public static void i4_to_halton(int dim_num, int step, int[] seed, int[] leap, int[] base_, ref double[] r) //****************************************************************************80 // // Purpose: // // I4_TO_HALTON computes one element of a leaped Halton subsequence. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 16 July 2004 // // Author: // // John Burkardt // // Reference: // // J H Halton, // On the efficiency of certain quasi-random sequences of points // in evaluating multi-dimensional integrals, // Numerische Mathematik, // Volume 2, 1960, pages 84-90. // // J H Halton and G B Smith, // Algorithm 247: Radical-Inverse Quasi-Random Point Sequence, // Communications of the ACM, // Volume 7, 1964, pages 701-702. // // Ladislav Kocis and William Whiten, // Computational Investigations of Low-Discrepancy Sequences, // ACM Transactions on Mathematical Software, // Volume 23, Number 2, 1997, pages 266-294. // // Parameters: // // Input, int DIM_NUM, the spatial dimension. // 1 <= DIM_NUM is required. // // Input, int STEP, the index of the subsequence element. // 0 <= STEP is required. // // Input, int SEED[DIM_NUM], the Halton sequence index corresponding // to STEP = 0. // 0 <= SEED(1:DIM_NUM) is required. // // Input, int LEAP[DIM_NUM], the successive jumps in the Halton sequence. // 1 <= LEAP(1:DIM_NUM) is required. // // Input, int BASE[DIM_NUM], the Halton bases. // 1 < BASE(1:DIM_NUM) is required. // // Output, double R[DIM_NUM], the STEP-th element of the leaped // Halton subsequence. // { int i; // // Check the input. // if (!Halham.halham_dim_num_check(dim_num)) { return; } if (!Halham.halham_step_check(step)) { return; } if (!Halham.halham_seed_check(dim_num, seed)) { return; } if (!Halham.halham_leap_check(dim_num, leap)) { return; } if (!halton_base_check(dim_num, base_)) { return; } // // Calculate the data. // for (i = 0; i < dim_num; i++) { int seed2 = seed[i] + step * leap[i]; r[i] = 0.0; double base_inv = 1.0 / base_[i]; while (seed2 != 0) { int digit = seed2 % base_[i]; r[i] += digit * base_inv; base_inv /= base_[i]; seed2 /= base_[i]; } } }
public static void i4_to_hammersley(int dim_num, int step, int[] seed, int[] leap, int[] base_, ref double[] r) //****************************************************************************80 // // Purpose: // // I4_TO_HAMMERSLEY computes one element of a leaped Hammersley subsequence. // // Discussion: // // The DIM_NUM-dimensional Hammersley sequence is really DIM_NUM separate // sequences, each generated by a particular base. If the base is // greater than 1, a standard 1-dimensional // van der Corput sequence is generated. But if the base is // negative, this is a signal that the much simpler sequence J/(-BASE) // is to be generated. For the standard Hammersley sequence, the // first spatial coordinate uses a base of (-N), and subsequent // coordinates use bases of successive primes (2, 3, 5, 7, 11, ...). // This program allows the user to specify any combination of bases, // included nonprimes and repeated values. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 30 September 2004 // // Author: // // John Burkardt // // Reference: // // J M Hammersley, // Monte Carlo methods for solving multivariable problems, // Proceedings of the New York Academy of Science, // Volume 86, 1960, pages 844-874. // // Ladislav Kocis and William Whiten, // Computational Investigations of Low-Discrepancy Sequences, // ACM Transactions on Mathematical Software, // Volume 23, Number 2, 1997, pages 266-294. // // Parameters: // // Input, int DIM_NUM, the spatial dimension. // 1 <= DIM_NUM is required. // // Input, int STEP, the index of the subsequence element. // 0 <= STEP is required. // // Input, int SEED[DIM_NUM], the Hammersley sequence index corresponding // to STEP = 0. // 0 <= SEED(1:DIM_NUM) is required. // // Input, int LEAP[DIM_NUM], the successive jumps in the Hammersley sequence. // 1 <= LEAP(1:DIM_NUM) is required. // // Input, int BASE[DIM_NUM], the Hammersley bases. // // Output, double R[DIM_NUM], the STEP-th element of the leaped // Hammersley subsequence. // { const double FIDDLE = 0.0; int i; // // Check the input. // if (!Halham.halham_dim_num_check(dim_num)) { return; } if (!Halham.halham_step_check(step)) { return; } if (!Halham.halham_seed_check(dim_num, seed)) { return; } if (!Halham.halham_leap_check(dim_num, seed)) { return; } if (!hammersley_base_check(dim_num, base_)) { return; } // // Calculate the data. // for (i = 0; i < dim_num; i++) { switch (base_[i]) { case > 1: { int seed2 = seed[i] + step * leap[i]; r[i] = 0.0; double base_inv = 1.0 / base_[i]; while (seed2 != 0) { int digit = seed2 % base_[i]; r[i] += digit * base_inv; base_inv /= base_[i]; seed2 /= base_[i]; } break; } // default: int temp = (seed[i] + step * leap[i]) % -base_[i]; r[i] = (temp + FIDDLE) / -base_[i]; break; } } }