libcrbn/sampler/faure.hpp

00001 #ifndef _FAURE_HPP_
00002 #define _FAURE_HPP_
00003 
00004 // Generate faure permutation matrix
00005 int** faure(const int& iSize) {
00006         int** permutation;
00007         int   i,j;
00008         
00009         if(iSize < 3) return 0;
00010         
00011         permutation = new (int*)[iSize];
00012 
00013         permutation[0] = 0;
00014 
00015         permutation[1] = new int[2];
00016         permutation[1][0] = 0;
00017         permutation[1][1] = 1;
00018 
00019         for(i = 3; i < iSize; ++i) {
00020                 permutation[i-1] = new int[i];
00021 
00022                 /* odd */       
00023                 if(i & 1) {
00024                         for(j = 0; j < ((i-1)/2); ++j) {
00025                                 if((2 * permutation[i-2][j]) >= (i-1)) {
00026                                         permutation[i-1][j] = permutation[i-2][j] + 1;
00027                                 }
00028                                 else {
00029                                         permutation[i-1][j] = permutation[i-2][j];
00030                                 }
00031                         }
00032 
00033                         permutation[i-1][(i-1)/2] = (i-1) / 2;
00034 
00035                         for(j = (i+1)/2; j < i; ++j) {
00036                                 if((2 * permutation[i-2][j-1]) >= (i-1)) {
00037                                         permutation[i-1][j] = permutation[i-2][j-1] + 1;
00038                                 }
00039                                 else {
00040                                         permutation[i-1][j] = permutation[i-2][j-1];
00041                                 }
00042                         }
00043                 }
00044                 /* even */
00045                 else {
00046                         for(j = 0; j < (i/2); ++j) {
00047                                 permutation[i-1][j] = 2 * permutation[(i/2)-1][j];
00048                         }
00049 
00050                         for(j = i/2; j < i; ++j) {
00051                                 permutation[i-1][j] = permutation[i-1][j-(i/2)] + 1;
00052                         }
00053                 }
00054         }
00055         
00056         return permutation;
00057 }
00058 
00059 #endif

Generated on Tue Nov 14 15:40:08 2006 for libcrbn by  doxygen 1.5.0