-
Notifications
You must be signed in to change notification settings - Fork 0
/
halton_sampler.h
3289 lines (3015 loc) · 136 KB
/
halton_sampler.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) 2012 Leonhard Gruenschloss ([email protected])
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
// This file is automatically generated.
#ifndef HALTON_SAMPLER_H
#define HALTON_SAMPLER_H
#include <algorithm>
#include <vector>
// Compute points of the Halton sequence with with digit-permutations for different bases.
class Halton_sampler
{
public:
// Init the permutation arrays using Faure-permutations. Alternatively, init_random can be
// called before the sampling functionality can be used.
void init_faure();
// Init the permutation arrays using randomized permutations. Alternatively, init_faure can be
// called before the sampling functionality can be used. The client needs to specify a random
// number generator function object that can be used to generate a random sequence of integers.
// That is: if f is a random number generator and N is a positive integer, then f(N) will
// return an integer less than N and greater than or equal to 0.
template <typename Random_number_generator>
void init_random(Random_number_generator& rand);
// Return the number of supported dimensions.
static unsigned get_num_dimensions() { return 256u; }
// Return the Halton sample for the given dimension (component) and index.
// The client must have called init_random or init_faure at least once before.
// dimension must be smaller than the value returned by get_num_dimensions().
float sample(unsigned dimension, unsigned index) const;
private:
static unsigned short invert(unsigned short base, unsigned short digits,
unsigned short index, const std::vector<unsigned short>& perm);
void init_tables(const std::vector<std::vector<unsigned short> >& perms);
float halton2(unsigned index) const;
float halton3(unsigned index) const;
float halton5(unsigned index) const;
float halton7(unsigned index) const;
float halton11(unsigned index) const;
float halton13(unsigned index) const;
float halton17(unsigned index) const;
float halton19(unsigned index) const;
float halton23(unsigned index) const;
float halton29(unsigned index) const;
float halton31(unsigned index) const;
float halton37(unsigned index) const;
float halton41(unsigned index) const;
float halton43(unsigned index) const;
float halton47(unsigned index) const;
float halton53(unsigned index) const;
float halton59(unsigned index) const;
float halton61(unsigned index) const;
float halton67(unsigned index) const;
float halton71(unsigned index) const;
float halton73(unsigned index) const;
float halton79(unsigned index) const;
float halton83(unsigned index) const;
float halton89(unsigned index) const;
float halton97(unsigned index) const;
float halton101(unsigned index) const;
float halton103(unsigned index) const;
float halton107(unsigned index) const;
float halton109(unsigned index) const;
float halton113(unsigned index) const;
float halton127(unsigned index) const;
float halton131(unsigned index) const;
float halton137(unsigned index) const;
float halton139(unsigned index) const;
float halton149(unsigned index) const;
float halton151(unsigned index) const;
float halton157(unsigned index) const;
float halton163(unsigned index) const;
float halton167(unsigned index) const;
float halton173(unsigned index) const;
float halton179(unsigned index) const;
float halton181(unsigned index) const;
float halton191(unsigned index) const;
float halton193(unsigned index) const;
float halton197(unsigned index) const;
float halton199(unsigned index) const;
float halton211(unsigned index) const;
float halton223(unsigned index) const;
float halton227(unsigned index) const;
float halton229(unsigned index) const;
float halton233(unsigned index) const;
float halton239(unsigned index) const;
float halton241(unsigned index) const;
float halton251(unsigned index) const;
float halton257(unsigned index) const;
float halton263(unsigned index) const;
float halton269(unsigned index) const;
float halton271(unsigned index) const;
float halton277(unsigned index) const;
float halton281(unsigned index) const;
float halton283(unsigned index) const;
float halton293(unsigned index) const;
float halton307(unsigned index) const;
float halton311(unsigned index) const;
float halton313(unsigned index) const;
float halton317(unsigned index) const;
float halton331(unsigned index) const;
float halton337(unsigned index) const;
float halton347(unsigned index) const;
float halton349(unsigned index) const;
float halton353(unsigned index) const;
float halton359(unsigned index) const;
float halton367(unsigned index) const;
float halton373(unsigned index) const;
float halton379(unsigned index) const;
float halton383(unsigned index) const;
float halton389(unsigned index) const;
float halton397(unsigned index) const;
float halton401(unsigned index) const;
float halton409(unsigned index) const;
float halton419(unsigned index) const;
float halton421(unsigned index) const;
float halton431(unsigned index) const;
float halton433(unsigned index) const;
float halton439(unsigned index) const;
float halton443(unsigned index) const;
float halton449(unsigned index) const;
float halton457(unsigned index) const;
float halton461(unsigned index) const;
float halton463(unsigned index) const;
float halton467(unsigned index) const;
float halton479(unsigned index) const;
float halton487(unsigned index) const;
float halton491(unsigned index) const;
float halton499(unsigned index) const;
float halton503(unsigned index) const;
float halton509(unsigned index) const;
float halton521(unsigned index) const;
float halton523(unsigned index) const;
float halton541(unsigned index) const;
float halton547(unsigned index) const;
float halton557(unsigned index) const;
float halton563(unsigned index) const;
float halton569(unsigned index) const;
float halton571(unsigned index) const;
float halton577(unsigned index) const;
float halton587(unsigned index) const;
float halton593(unsigned index) const;
float halton599(unsigned index) const;
float halton601(unsigned index) const;
float halton607(unsigned index) const;
float halton613(unsigned index) const;
float halton617(unsigned index) const;
float halton619(unsigned index) const;
float halton631(unsigned index) const;
float halton641(unsigned index) const;
float halton643(unsigned index) const;
float halton647(unsigned index) const;
float halton653(unsigned index) const;
float halton659(unsigned index) const;
float halton661(unsigned index) const;
float halton673(unsigned index) const;
float halton677(unsigned index) const;
float halton683(unsigned index) const;
float halton691(unsigned index) const;
float halton701(unsigned index) const;
float halton709(unsigned index) const;
float halton719(unsigned index) const;
float halton727(unsigned index) const;
float halton733(unsigned index) const;
float halton739(unsigned index) const;
float halton743(unsigned index) const;
float halton751(unsigned index) const;
float halton757(unsigned index) const;
float halton761(unsigned index) const;
float halton769(unsigned index) const;
float halton773(unsigned index) const;
float halton787(unsigned index) const;
float halton797(unsigned index) const;
float halton809(unsigned index) const;
float halton811(unsigned index) const;
float halton821(unsigned index) const;
float halton823(unsigned index) const;
float halton827(unsigned index) const;
float halton829(unsigned index) const;
float halton839(unsigned index) const;
float halton853(unsigned index) const;
float halton857(unsigned index) const;
float halton859(unsigned index) const;
float halton863(unsigned index) const;
float halton877(unsigned index) const;
float halton881(unsigned index) const;
float halton883(unsigned index) const;
float halton887(unsigned index) const;
float halton907(unsigned index) const;
float halton911(unsigned index) const;
float halton919(unsigned index) const;
float halton929(unsigned index) const;
float halton937(unsigned index) const;
float halton941(unsigned index) const;
float halton947(unsigned index) const;
float halton953(unsigned index) const;
float halton967(unsigned index) const;
float halton971(unsigned index) const;
float halton977(unsigned index) const;
float halton983(unsigned index) const;
float halton991(unsigned index) const;
float halton997(unsigned index) const;
float halton1009(unsigned index) const;
float halton1013(unsigned index) const;
float halton1019(unsigned index) const;
float halton1021(unsigned index) const;
float halton1031(unsigned index) const;
float halton1033(unsigned index) const;
float halton1039(unsigned index) const;
float halton1049(unsigned index) const;
float halton1051(unsigned index) const;
float halton1061(unsigned index) const;
float halton1063(unsigned index) const;
float halton1069(unsigned index) const;
float halton1087(unsigned index) const;
float halton1091(unsigned index) const;
float halton1093(unsigned index) const;
float halton1097(unsigned index) const;
float halton1103(unsigned index) const;
float halton1109(unsigned index) const;
float halton1117(unsigned index) const;
float halton1123(unsigned index) const;
float halton1129(unsigned index) const;
float halton1151(unsigned index) const;
float halton1153(unsigned index) const;
float halton1163(unsigned index) const;
float halton1171(unsigned index) const;
float halton1181(unsigned index) const;
float halton1187(unsigned index) const;
float halton1193(unsigned index) const;
float halton1201(unsigned index) const;
float halton1213(unsigned index) const;
float halton1217(unsigned index) const;
float halton1223(unsigned index) const;
float halton1229(unsigned index) const;
float halton1231(unsigned index) const;
float halton1237(unsigned index) const;
float halton1249(unsigned index) const;
float halton1259(unsigned index) const;
float halton1277(unsigned index) const;
float halton1279(unsigned index) const;
float halton1283(unsigned index) const;
float halton1289(unsigned index) const;
float halton1291(unsigned index) const;
float halton1297(unsigned index) const;
float halton1301(unsigned index) const;
float halton1303(unsigned index) const;
float halton1307(unsigned index) const;
float halton1319(unsigned index) const;
float halton1321(unsigned index) const;
float halton1327(unsigned index) const;
float halton1361(unsigned index) const;
float halton1367(unsigned index) const;
float halton1373(unsigned index) const;
float halton1381(unsigned index) const;
float halton1399(unsigned index) const;
float halton1409(unsigned index) const;
float halton1423(unsigned index) const;
float halton1427(unsigned index) const;
float halton1429(unsigned index) const;
float halton1433(unsigned index) const;
float halton1439(unsigned index) const;
float halton1447(unsigned index) const;
float halton1451(unsigned index) const;
float halton1453(unsigned index) const;
float halton1459(unsigned index) const;
float halton1471(unsigned index) const;
float halton1481(unsigned index) const;
float halton1483(unsigned index) const;
float halton1487(unsigned index) const;
float halton1489(unsigned index) const;
float halton1493(unsigned index) const;
float halton1499(unsigned index) const;
float halton1511(unsigned index) const;
float halton1523(unsigned index) const;
float halton1531(unsigned index) const;
float halton1543(unsigned index) const;
float halton1549(unsigned index) const;
float halton1553(unsigned index) const;
float halton1559(unsigned index) const;
float halton1567(unsigned index) const;
float halton1571(unsigned index) const;
float halton1579(unsigned index) const;
float halton1583(unsigned index) const;
float halton1597(unsigned index) const;
float halton1601(unsigned index) const;
float halton1607(unsigned index) const;
float halton1609(unsigned index) const;
float halton1613(unsigned index) const;
float halton1619(unsigned index) const;
unsigned short m_perm3[243];
unsigned short m_perm5[125];
unsigned short m_perm7[343];
unsigned short m_perm11[121];
unsigned short m_perm13[169];
unsigned short m_perm17[289];
unsigned short m_perm19[361];
unsigned short m_perm23[23];
unsigned short m_perm29[29];
unsigned short m_perm31[31];
unsigned short m_perm37[37];
unsigned short m_perm41[41];
unsigned short m_perm43[43];
unsigned short m_perm47[47];
unsigned short m_perm53[53];
unsigned short m_perm59[59];
unsigned short m_perm61[61];
unsigned short m_perm67[67];
unsigned short m_perm71[71];
unsigned short m_perm73[73];
unsigned short m_perm79[79];
unsigned short m_perm83[83];
unsigned short m_perm89[89];
unsigned short m_perm97[97];
unsigned short m_perm101[101];
unsigned short m_perm103[103];
unsigned short m_perm107[107];
unsigned short m_perm109[109];
unsigned short m_perm113[113];
unsigned short m_perm127[127];
unsigned short m_perm131[131];
unsigned short m_perm137[137];
unsigned short m_perm139[139];
unsigned short m_perm149[149];
unsigned short m_perm151[151];
unsigned short m_perm157[157];
unsigned short m_perm163[163];
unsigned short m_perm167[167];
unsigned short m_perm173[173];
unsigned short m_perm179[179];
unsigned short m_perm181[181];
unsigned short m_perm191[191];
unsigned short m_perm193[193];
unsigned short m_perm197[197];
unsigned short m_perm199[199];
unsigned short m_perm211[211];
unsigned short m_perm223[223];
unsigned short m_perm227[227];
unsigned short m_perm229[229];
unsigned short m_perm233[233];
unsigned short m_perm239[239];
unsigned short m_perm241[241];
unsigned short m_perm251[251];
unsigned short m_perm257[257];
unsigned short m_perm263[263];
unsigned short m_perm269[269];
unsigned short m_perm271[271];
unsigned short m_perm277[277];
unsigned short m_perm281[281];
unsigned short m_perm283[283];
unsigned short m_perm293[293];
unsigned short m_perm307[307];
unsigned short m_perm311[311];
unsigned short m_perm313[313];
unsigned short m_perm317[317];
unsigned short m_perm331[331];
unsigned short m_perm337[337];
unsigned short m_perm347[347];
unsigned short m_perm349[349];
unsigned short m_perm353[353];
unsigned short m_perm359[359];
unsigned short m_perm367[367];
unsigned short m_perm373[373];
unsigned short m_perm379[379];
unsigned short m_perm383[383];
unsigned short m_perm389[389];
unsigned short m_perm397[397];
unsigned short m_perm401[401];
unsigned short m_perm409[409];
unsigned short m_perm419[419];
unsigned short m_perm421[421];
unsigned short m_perm431[431];
unsigned short m_perm433[433];
unsigned short m_perm439[439];
unsigned short m_perm443[443];
unsigned short m_perm449[449];
unsigned short m_perm457[457];
unsigned short m_perm461[461];
unsigned short m_perm463[463];
unsigned short m_perm467[467];
unsigned short m_perm479[479];
unsigned short m_perm487[487];
unsigned short m_perm491[491];
unsigned short m_perm499[499];
unsigned short m_perm503[503];
unsigned short m_perm509[509];
unsigned short m_perm521[521];
unsigned short m_perm523[523];
unsigned short m_perm541[541];
unsigned short m_perm547[547];
unsigned short m_perm557[557];
unsigned short m_perm563[563];
unsigned short m_perm569[569];
unsigned short m_perm571[571];
unsigned short m_perm577[577];
unsigned short m_perm587[587];
unsigned short m_perm593[593];
unsigned short m_perm599[599];
unsigned short m_perm601[601];
unsigned short m_perm607[607];
unsigned short m_perm613[613];
unsigned short m_perm617[617];
unsigned short m_perm619[619];
unsigned short m_perm631[631];
unsigned short m_perm641[641];
unsigned short m_perm643[643];
unsigned short m_perm647[647];
unsigned short m_perm653[653];
unsigned short m_perm659[659];
unsigned short m_perm661[661];
unsigned short m_perm673[673];
unsigned short m_perm677[677];
unsigned short m_perm683[683];
unsigned short m_perm691[691];
unsigned short m_perm701[701];
unsigned short m_perm709[709];
unsigned short m_perm719[719];
unsigned short m_perm727[727];
unsigned short m_perm733[733];
unsigned short m_perm739[739];
unsigned short m_perm743[743];
unsigned short m_perm751[751];
unsigned short m_perm757[757];
unsigned short m_perm761[761];
unsigned short m_perm769[769];
unsigned short m_perm773[773];
unsigned short m_perm787[787];
unsigned short m_perm797[797];
unsigned short m_perm809[809];
unsigned short m_perm811[811];
unsigned short m_perm821[821];
unsigned short m_perm823[823];
unsigned short m_perm827[827];
unsigned short m_perm829[829];
unsigned short m_perm839[839];
unsigned short m_perm853[853];
unsigned short m_perm857[857];
unsigned short m_perm859[859];
unsigned short m_perm863[863];
unsigned short m_perm877[877];
unsigned short m_perm881[881];
unsigned short m_perm883[883];
unsigned short m_perm887[887];
unsigned short m_perm907[907];
unsigned short m_perm911[911];
unsigned short m_perm919[919];
unsigned short m_perm929[929];
unsigned short m_perm937[937];
unsigned short m_perm941[941];
unsigned short m_perm947[947];
unsigned short m_perm953[953];
unsigned short m_perm967[967];
unsigned short m_perm971[971];
unsigned short m_perm977[977];
unsigned short m_perm983[983];
unsigned short m_perm991[991];
unsigned short m_perm997[997];
unsigned short m_perm1009[1009];
unsigned short m_perm1013[1013];
unsigned short m_perm1019[1019];
unsigned short m_perm1021[1021];
unsigned short m_perm1031[1031];
unsigned short m_perm1033[1033];
unsigned short m_perm1039[1039];
unsigned short m_perm1049[1049];
unsigned short m_perm1051[1051];
unsigned short m_perm1061[1061];
unsigned short m_perm1063[1063];
unsigned short m_perm1069[1069];
unsigned short m_perm1087[1087];
unsigned short m_perm1091[1091];
unsigned short m_perm1093[1093];
unsigned short m_perm1097[1097];
unsigned short m_perm1103[1103];
unsigned short m_perm1109[1109];
unsigned short m_perm1117[1117];
unsigned short m_perm1123[1123];
unsigned short m_perm1129[1129];
unsigned short m_perm1151[1151];
unsigned short m_perm1153[1153];
unsigned short m_perm1163[1163];
unsigned short m_perm1171[1171];
unsigned short m_perm1181[1181];
unsigned short m_perm1187[1187];
unsigned short m_perm1193[1193];
unsigned short m_perm1201[1201];
unsigned short m_perm1213[1213];
unsigned short m_perm1217[1217];
unsigned short m_perm1223[1223];
unsigned short m_perm1229[1229];
unsigned short m_perm1231[1231];
unsigned short m_perm1237[1237];
unsigned short m_perm1249[1249];
unsigned short m_perm1259[1259];
unsigned short m_perm1277[1277];
unsigned short m_perm1279[1279];
unsigned short m_perm1283[1283];
unsigned short m_perm1289[1289];
unsigned short m_perm1291[1291];
unsigned short m_perm1297[1297];
unsigned short m_perm1301[1301];
unsigned short m_perm1303[1303];
unsigned short m_perm1307[1307];
unsigned short m_perm1319[1319];
unsigned short m_perm1321[1321];
unsigned short m_perm1327[1327];
unsigned short m_perm1361[1361];
unsigned short m_perm1367[1367];
unsigned short m_perm1373[1373];
unsigned short m_perm1381[1381];
unsigned short m_perm1399[1399];
unsigned short m_perm1409[1409];
unsigned short m_perm1423[1423];
unsigned short m_perm1427[1427];
unsigned short m_perm1429[1429];
unsigned short m_perm1433[1433];
unsigned short m_perm1439[1439];
unsigned short m_perm1447[1447];
unsigned short m_perm1451[1451];
unsigned short m_perm1453[1453];
unsigned short m_perm1459[1459];
unsigned short m_perm1471[1471];
unsigned short m_perm1481[1481];
unsigned short m_perm1483[1483];
unsigned short m_perm1487[1487];
unsigned short m_perm1489[1489];
unsigned short m_perm1493[1493];
unsigned short m_perm1499[1499];
unsigned short m_perm1511[1511];
unsigned short m_perm1523[1523];
unsigned short m_perm1531[1531];
unsigned short m_perm1543[1543];
unsigned short m_perm1549[1549];
unsigned short m_perm1553[1553];
unsigned short m_perm1559[1559];
unsigned short m_perm1567[1567];
unsigned short m_perm1571[1571];
unsigned short m_perm1579[1579];
unsigned short m_perm1583[1583];
unsigned short m_perm1597[1597];
unsigned short m_perm1601[1601];
unsigned short m_perm1607[1607];
unsigned short m_perm1609[1609];
unsigned short m_perm1613[1613];
unsigned short m_perm1619[1619];
};
inline void Halton_sampler::init_faure()
{
const unsigned max_base = 1619u;
std::vector<std::vector<unsigned short> > perms(max_base + 1);
for (unsigned k = 1; k <= 3; ++k) // Keep identity permutations for base 1, 2, 3.
{
perms[k].resize(k);
for (unsigned i = 0; i < k; ++i)
perms[k][i] = i;
}
for (unsigned base = 4; base <= max_base; ++base)
{
perms[base].resize(base);
const unsigned b = base / 2;
if (base & 1) // odd
{
for (unsigned i = 0; i < base - 1; ++i)
perms[base][i + (i >= b)] = perms[base - 1][i] + (perms[base - 1][i] >= b);
perms[base][b] = b;
}
else // even
{
for (unsigned i = 0; i < b; ++i)
{
perms[base][i] = 2 * perms[b][i];
perms[base][b + i] = 2 * perms[b][i] + 1;
}
}
}
init_tables(perms);
}
template <typename Random_number_generator>
void Halton_sampler::init_random(Random_number_generator& rand)
{
const unsigned max_base = 1619u;
std::vector<std::vector<unsigned short> > perms(max_base + 1);
for (unsigned k = 1; k <= 3; ++k) // Keep identity permutations for base 1, 2, 3.
{
perms[k].resize(k);
for (unsigned i = 0; i < k; ++i)
perms[k][i] = i;
}
for (unsigned base = 4; base <= max_base; ++base)
{
perms[base].resize(base);
for (unsigned i = 0; i < base; ++i)
perms[base][i] = i;
std::random_shuffle(perms[base].begin(), perms[base].end(), rand);
}
init_tables(perms);
}
inline float Halton_sampler::sample(const unsigned dimension, const unsigned index) const
{
switch (dimension)
{
case 0: return halton2(index);
case 1: return halton3(index);
case 2: return halton5(index);
case 3: return halton7(index);
case 4: return halton11(index);
case 5: return halton13(index);
case 6: return halton17(index);
case 7: return halton19(index);
case 8: return halton23(index);
case 9: return halton29(index);
case 10: return halton31(index);
case 11: return halton37(index);
case 12: return halton41(index);
case 13: return halton43(index);
case 14: return halton47(index);
case 15: return halton53(index);
case 16: return halton59(index);
case 17: return halton61(index);
case 18: return halton67(index);
case 19: return halton71(index);
case 20: return halton73(index);
case 21: return halton79(index);
case 22: return halton83(index);
case 23: return halton89(index);
case 24: return halton97(index);
case 25: return halton101(index);
case 26: return halton103(index);
case 27: return halton107(index);
case 28: return halton109(index);
case 29: return halton113(index);
case 30: return halton127(index);
case 31: return halton131(index);
case 32: return halton137(index);
case 33: return halton139(index);
case 34: return halton149(index);
case 35: return halton151(index);
case 36: return halton157(index);
case 37: return halton163(index);
case 38: return halton167(index);
case 39: return halton173(index);
case 40: return halton179(index);
case 41: return halton181(index);
case 42: return halton191(index);
case 43: return halton193(index);
case 44: return halton197(index);
case 45: return halton199(index);
case 46: return halton211(index);
case 47: return halton223(index);
case 48: return halton227(index);
case 49: return halton229(index);
case 50: return halton233(index);
case 51: return halton239(index);
case 52: return halton241(index);
case 53: return halton251(index);
case 54: return halton257(index);
case 55: return halton263(index);
case 56: return halton269(index);
case 57: return halton271(index);
case 58: return halton277(index);
case 59: return halton281(index);
case 60: return halton283(index);
case 61: return halton293(index);
case 62: return halton307(index);
case 63: return halton311(index);
case 64: return halton313(index);
case 65: return halton317(index);
case 66: return halton331(index);
case 67: return halton337(index);
case 68: return halton347(index);
case 69: return halton349(index);
case 70: return halton353(index);
case 71: return halton359(index);
case 72: return halton367(index);
case 73: return halton373(index);
case 74: return halton379(index);
case 75: return halton383(index);
case 76: return halton389(index);
case 77: return halton397(index);
case 78: return halton401(index);
case 79: return halton409(index);
case 80: return halton419(index);
case 81: return halton421(index);
case 82: return halton431(index);
case 83: return halton433(index);
case 84: return halton439(index);
case 85: return halton443(index);
case 86: return halton449(index);
case 87: return halton457(index);
case 88: return halton461(index);
case 89: return halton463(index);
case 90: return halton467(index);
case 91: return halton479(index);
case 92: return halton487(index);
case 93: return halton491(index);
case 94: return halton499(index);
case 95: return halton503(index);
case 96: return halton509(index);
case 97: return halton521(index);
case 98: return halton523(index);
case 99: return halton541(index);
case 100: return halton547(index);
case 101: return halton557(index);
case 102: return halton563(index);
case 103: return halton569(index);
case 104: return halton571(index);
case 105: return halton577(index);
case 106: return halton587(index);
case 107: return halton593(index);
case 108: return halton599(index);
case 109: return halton601(index);
case 110: return halton607(index);
case 111: return halton613(index);
case 112: return halton617(index);
case 113: return halton619(index);
case 114: return halton631(index);
case 115: return halton641(index);
case 116: return halton643(index);
case 117: return halton647(index);
case 118: return halton653(index);
case 119: return halton659(index);
case 120: return halton661(index);
case 121: return halton673(index);
case 122: return halton677(index);
case 123: return halton683(index);
case 124: return halton691(index);
case 125: return halton701(index);
case 126: return halton709(index);
case 127: return halton719(index);
case 128: return halton727(index);
case 129: return halton733(index);
case 130: return halton739(index);
case 131: return halton743(index);
case 132: return halton751(index);
case 133: return halton757(index);
case 134: return halton761(index);
case 135: return halton769(index);
case 136: return halton773(index);
case 137: return halton787(index);
case 138: return halton797(index);
case 139: return halton809(index);
case 140: return halton811(index);
case 141: return halton821(index);
case 142: return halton823(index);
case 143: return halton827(index);
case 144: return halton829(index);
case 145: return halton839(index);
case 146: return halton853(index);
case 147: return halton857(index);
case 148: return halton859(index);
case 149: return halton863(index);
case 150: return halton877(index);
case 151: return halton881(index);
case 152: return halton883(index);
case 153: return halton887(index);
case 154: return halton907(index);
case 155: return halton911(index);
case 156: return halton919(index);
case 157: return halton929(index);
case 158: return halton937(index);
case 159: return halton941(index);
case 160: return halton947(index);
case 161: return halton953(index);
case 162: return halton967(index);
case 163: return halton971(index);
case 164: return halton977(index);
case 165: return halton983(index);
case 166: return halton991(index);
case 167: return halton997(index);
case 168: return halton1009(index);
case 169: return halton1013(index);
case 170: return halton1019(index);
case 171: return halton1021(index);
case 172: return halton1031(index);
case 173: return halton1033(index);
case 174: return halton1039(index);
case 175: return halton1049(index);
case 176: return halton1051(index);
case 177: return halton1061(index);
case 178: return halton1063(index);
case 179: return halton1069(index);
case 180: return halton1087(index);
case 181: return halton1091(index);
case 182: return halton1093(index);
case 183: return halton1097(index);
case 184: return halton1103(index);
case 185: return halton1109(index);
case 186: return halton1117(index);
case 187: return halton1123(index);
case 188: return halton1129(index);
case 189: return halton1151(index);
case 190: return halton1153(index);
case 191: return halton1163(index);
case 192: return halton1171(index);
case 193: return halton1181(index);
case 194: return halton1187(index);
case 195: return halton1193(index);
case 196: return halton1201(index);
case 197: return halton1213(index);
case 198: return halton1217(index);
case 199: return halton1223(index);
case 200: return halton1229(index);
case 201: return halton1231(index);
case 202: return halton1237(index);
case 203: return halton1249(index);
case 204: return halton1259(index);
case 205: return halton1277(index);
case 206: return halton1279(index);
case 207: return halton1283(index);
case 208: return halton1289(index);
case 209: return halton1291(index);
case 210: return halton1297(index);
case 211: return halton1301(index);
case 212: return halton1303(index);
case 213: return halton1307(index);
case 214: return halton1319(index);
case 215: return halton1321(index);
case 216: return halton1327(index);
case 217: return halton1361(index);
case 218: return halton1367(index);
case 219: return halton1373(index);
case 220: return halton1381(index);
case 221: return halton1399(index);
case 222: return halton1409(index);
case 223: return halton1423(index);
case 224: return halton1427(index);
case 225: return halton1429(index);
case 226: return halton1433(index);
case 227: return halton1439(index);
case 228: return halton1447(index);
case 229: return halton1451(index);
case 230: return halton1453(index);
case 231: return halton1459(index);
case 232: return halton1471(index);
case 233: return halton1481(index);
case 234: return halton1483(index);
case 235: return halton1487(index);
case 236: return halton1489(index);
case 237: return halton1493(index);
case 238: return halton1499(index);
case 239: return halton1511(index);
case 240: return halton1523(index);
case 241: return halton1531(index);
case 242: return halton1543(index);
case 243: return halton1549(index);
case 244: return halton1553(index);
case 245: return halton1559(index);
case 246: return halton1567(index);
case 247: return halton1571(index);
case 248: return halton1579(index);
case 249: return halton1583(index);
case 250: return halton1597(index);
case 251: return halton1601(index);
case 252: return halton1607(index);
case 253: return halton1609(index);
case 254: return halton1613(index);
case 255: return halton1619(index);
}
return 0.f;
}
inline unsigned short Halton_sampler::invert(const unsigned short base, const unsigned short digits,
unsigned short index, const std::vector<unsigned short>& perm)
{
unsigned short result = 0;
for (unsigned short i = 0; i < digits; ++i)
{
result = result * base + perm[index % base];
index /= base;
}
return result;
}
inline void Halton_sampler::init_tables(const std::vector<std::vector<unsigned short> >& perms)
{
for (unsigned short i = 0; i < 243; ++i)
m_perm3[i] = invert(3, 5, i, perms[3]);
for (unsigned short i = 0; i < 125; ++i)
m_perm5[i] = invert(5, 3, i, perms[5]);
for (unsigned short i = 0; i < 343; ++i)
m_perm7[i] = invert(7, 3, i, perms[7]);
for (unsigned short i = 0; i < 121; ++i)
m_perm11[i] = invert(11, 2, i, perms[11]);
for (unsigned short i = 0; i < 169; ++i)
m_perm13[i] = invert(13, 2, i, perms[13]);
for (unsigned short i = 0; i < 289; ++i)
m_perm17[i] = invert(17, 2, i, perms[17]);
for (unsigned short i = 0; i < 361; ++i)
m_perm19[i] = invert(19, 2, i, perms[19]);
for (unsigned short i = 0; i < 23; ++i)
m_perm23[i] = invert(23, 1, i, perms[23]);
for (unsigned short i = 0; i < 29; ++i)
m_perm29[i] = invert(29, 1, i, perms[29]);
for (unsigned short i = 0; i < 31; ++i)
m_perm31[i] = invert(31, 1, i, perms[31]);
for (unsigned short i = 0; i < 37; ++i)
m_perm37[i] = invert(37, 1, i, perms[37]);
for (unsigned short i = 0; i < 41; ++i)
m_perm41[i] = invert(41, 1, i, perms[41]);
for (unsigned short i = 0; i < 43; ++i)
m_perm43[i] = invert(43, 1, i, perms[43]);
for (unsigned short i = 0; i < 47; ++i)
m_perm47[i] = invert(47, 1, i, perms[47]);
for (unsigned short i = 0; i < 53; ++i)
m_perm53[i] = invert(53, 1, i, perms[53]);
for (unsigned short i = 0; i < 59; ++i)
m_perm59[i] = invert(59, 1, i, perms[59]);
for (unsigned short i = 0; i < 61; ++i)
m_perm61[i] = invert(61, 1, i, perms[61]);
for (unsigned short i = 0; i < 67; ++i)
m_perm67[i] = invert(67, 1, i, perms[67]);
for (unsigned short i = 0; i < 71; ++i)
m_perm71[i] = invert(71, 1, i, perms[71]);
for (unsigned short i = 0; i < 73; ++i)
m_perm73[i] = invert(73, 1, i, perms[73]);
for (unsigned short i = 0; i < 79; ++i)
m_perm79[i] = invert(79, 1, i, perms[79]);
for (unsigned short i = 0; i < 83; ++i)
m_perm83[i] = invert(83, 1, i, perms[83]);
for (unsigned short i = 0; i < 89; ++i)
m_perm89[i] = invert(89, 1, i, perms[89]);
for (unsigned short i = 0; i < 97; ++i)
m_perm97[i] = invert(97, 1, i, perms[97]);
for (unsigned short i = 0; i < 101; ++i)
m_perm101[i] = invert(101, 1, i, perms[101]);
for (unsigned short i = 0; i < 103; ++i)
m_perm103[i] = invert(103, 1, i, perms[103]);
for (unsigned short i = 0; i < 107; ++i)
m_perm107[i] = invert(107, 1, i, perms[107]);
for (unsigned short i = 0; i < 109; ++i)
m_perm109[i] = invert(109, 1, i, perms[109]);
for (unsigned short i = 0; i < 113; ++i)
m_perm113[i] = invert(113, 1, i, perms[113]);
for (unsigned short i = 0; i < 127; ++i)
m_perm127[i] = invert(127, 1, i, perms[127]);
for (unsigned short i = 0; i < 131; ++i)
m_perm131[i] = invert(131, 1, i, perms[131]);
for (unsigned short i = 0; i < 137; ++i)
m_perm137[i] = invert(137, 1, i, perms[137]);
for (unsigned short i = 0; i < 139; ++i)
m_perm139[i] = invert(139, 1, i, perms[139]);
for (unsigned short i = 0; i < 149; ++i)
m_perm149[i] = invert(149, 1, i, perms[149]);
for (unsigned short i = 0; i < 151; ++i)
m_perm151[i] = invert(151, 1, i, perms[151]);
for (unsigned short i = 0; i < 157; ++i)
m_perm157[i] = invert(157, 1, i, perms[157]);
for (unsigned short i = 0; i < 163; ++i)
m_perm163[i] = invert(163, 1, i, perms[163]);
for (unsigned short i = 0; i < 167; ++i)
m_perm167[i] = invert(167, 1, i, perms[167]);
for (unsigned short i = 0; i < 173; ++i)
m_perm173[i] = invert(173, 1, i, perms[173]);
for (unsigned short i = 0; i < 179; ++i)
m_perm179[i] = invert(179, 1, i, perms[179]);
for (unsigned short i = 0; i < 181; ++i)
m_perm181[i] = invert(181, 1, i, perms[181]);
for (unsigned short i = 0; i < 191; ++i)
m_perm191[i] = invert(191, 1, i, perms[191]);
for (unsigned short i = 0; i < 193; ++i)
m_perm193[i] = invert(193, 1, i, perms[193]);
for (unsigned short i = 0; i < 197; ++i)
m_perm197[i] = invert(197, 1, i, perms[197]);
for (unsigned short i = 0; i < 199; ++i)
m_perm199[i] = invert(199, 1, i, perms[199]);
for (unsigned short i = 0; i < 211; ++i)
m_perm211[i] = invert(211, 1, i, perms[211]);
for (unsigned short i = 0; i < 223; ++i)
m_perm223[i] = invert(223, 1, i, perms[223]);
for (unsigned short i = 0; i < 227; ++i)
m_perm227[i] = invert(227, 1, i, perms[227]);
for (unsigned short i = 0; i < 229; ++i)