88
99class SobolSampling (Sampling ):
1010
11- def __init__ (self , n_skip = - 1 , n_leap = 0 , setup = "matlab" ) -> None :
11+ def __init__ (self , n_skip = None , n_leap = 0 , setup = "matlab" ) -> None :
1212 super ().__init__ ()
13- fname = "sobol_%s.dat" % setup
14- self .setup = parse_file (path_to_resources (fname ))
1513
14+ if setup == "matlab" :
15+ if n_skip is None :
16+ n_skip = 0
17+ max_bits = 53
18+ fname = "sobol_matlab.dat"
19+
20+ elif setup == "burkardt" :
21+ if n_skip is None :
22+ n_skip = - 1
23+ max_bits = 32
24+ fname = "sobol_burkardt.dat"
25+
26+ elif setup == "joekuo" :
27+ if n_skip is None :
28+ n_skip = 0
29+ max_bits = 32
30+ fname = "sobol_joekuo.dat"
31+
32+ else :
33+ raise Exception ("Unkonwn setup." )
34+
35+ self .setup = parse_file (path_to_resources (fname ))
1636 self .n_skip = n_skip
1737 self .n_leap = n_leap
38+ self .max_bits = max_bits
1839
1940 def _sample (self , n_samples , n_dim ):
2041
@@ -26,7 +47,7 @@ def _sample(self, n_samples, n_dim):
2647 I += self .n_skip
2748 n_sequence = np .max (I ) + 1
2849
29- # containts all the values of the sequences as integer
50+ # contains all the values of the sequences as integer
3051 _X = np .zeros ((n_sequence , n_dim ), dtype = np .int )
3152
3253 # number of bits which will be necessary for this sequence
@@ -38,7 +59,7 @@ def _sample(self, n_samples, n_dim):
3859 for j in range (n_dim ):
3960
4061 if j == 0 :
41- V = np .concatenate ((np .array ([0 ]), 2 ** np .arange (31 , - 1 , - 1 )))
62+ V = np .concatenate ((np .array ([0 ]), 2 ** np .arange (self . max_bits - 1 , - 1 , - 1 )))
4263
4364 else :
4465
@@ -47,12 +68,12 @@ def _sample(self, n_samples, n_dim):
4768
4869 if L <= s :
4970 for k in range (1 , L + 1 ):
50- V [k ] = m [k - 1 ] << (32 - k )
71+ V [k ] = m [k - 1 ] << (self . max_bits - k )
5172
5273 else :
5374
5475 for k in range (1 , s + 1 ):
55- V [k ] = m [k - 1 ] << (32 - k )
76+ V [k ] = m [k - 1 ] << (self . max_bits - k )
5677
5778 for i in range (s + 1 , L + 1 ):
5879 V [i ] = V [i - s ] ^ int (V [i - s ] >> s )
@@ -62,7 +83,7 @@ def _sample(self, n_samples, n_dim):
6283 for i in range (1 , n_sequence ):
6384 _X [i , j ] = _X [i - 1 , j ] ^ V [C [i - 1 ]]
6485
65- X = (_X / 2 ** 32 )[I ]
86+ X = (_X / 2 ** self . max_bits )[I ]
6687 return X
6788
6889
0 commit comments