-
Notifications
You must be signed in to change notification settings - Fork 22
Lattice kronecker #556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Lattice kronecker #556
Changes from all commits
65871dc
b3d48fd
4350e46
1e969b5
1ff125d
78e67bc
cef4e70
c33611e
8864860
bc3d3b6
ee0a1a0
82d8df4
29cea0b
9033e59
15ee863
081936c
a48c42e
cfbe5ec
a4055a1
cfbcf9c
2a3bbb4
b0889dc
98221ba
2542d0d
dea6e2c
fe041c4
c98da32
9874b96
e8e8290
24e2195
0a6bc4e
d87eca5
f223ce7
8b34133
86bae71
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| from .kronecker import Kronecker | ||
| from .kronecker_search_methods import kronecker_vector_search_mobius_transform |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| 0.618033988749895 | ||
| 0.3173225474723 | ||
| 0.59332263014446 | ||
| 0.20776441643926 | ||
| 0.27373719258623 | ||
| 0.649734278361753 | ||
| 0.478954018631769 | ||
| 0.86866022435182 | ||
| 0.22845082022244 | ||
| 0.581365429377986 | ||
| 0.282365231829842 | ||
| 0.0822850909119904 | ||
| 0.223849641007295 | ||
| 0.5770772201756 | ||
| 0.51769659336634 | ||
| 0.568025390904592 | ||
| 0.156782234569368 | ||
| 0.82246227056154 | ||
| 0.805675312097409 | ||
| 0.63877102813393 | ||
| 0.358300563495856 | ||
| 0.241741343018598 | ||
| 0.705003192174204 | ||
| 0.1931911954956 | ||
| 0.261022001488623 | ||
| 0.897938992038015 | ||
| 0.46839743115877 | ||
| 0.884022067965329 | ||
| 0.752352896871505 | ||
| 0.1601583600427 | ||
| 0.10727599509739 | ||
| 0.151478435512877 | ||
| 0.163863657127101 | ||
| 0.948303450359399 | ||
| 0.80350943597439 | ||
| 0.426371623468333 | ||
| 0.435930910910882 | ||
| 0.21329852459791 | ||
| 0.661698149534002 | ||
| 0.900679822160453 | ||
| 0.122436710671457 | ||
| 0.483663584095611 | ||
| 0.928181067731583 | ||
| 0.443143014606576 | ||
| 0.74491332336194 | ||
| 0.87948409225588 | ||
| 0.0428242449803 | ||
| 0.534576896789579 | ||
| 0.24340042100879 | ||
| 0.30424418245585 | ||
| 0.574003104342617 | ||
| 0.897289023268963 | ||
| 0.541424476559586 | ||
| 0.356895660350464 | ||
| 0.507567280910795 | ||
| 0.513983550428507 | ||
| 0.0610821922457415 | ||
| 0.183871471606587 | ||
| 0.446015178033969 | ||
| 0.455684287415085 | ||
| 0.280817534817491 | ||
| 0.115220095666085 | ||
| 0.433740673279323 | ||
| 0.515605957977756 | ||
| 0.113076735656464 | ||
| 0.733928297688305 | ||
| 0.0597515651584137 | ||
| 0.422268695684775 | ||
| 0.0979181139173599 | ||
| 0.213699261322352 | ||
| 0.866811679881922 | ||
| 0.0878569329036737 | ||
| 0.678412735893121 | ||
| 0.181093969536107 | ||
| 0.128913741473518 | ||
| 0.109341703717108 | ||
| 0.289067270578427 | ||
| 0.352218331663839 | ||
| 0.303605902333137 | ||
| 0.0613899204730832 | ||
| 0.959535877660851 | ||
| 0.475508309069064 | ||
| 0.688698902674194 | ||
| 0.657037932118495 | ||
| 0.645555897563869 | ||
| 0.720658665263604 | ||
| 0.914423387894897 | ||
| 0.425763295044487 | ||
| 0.328825255006553 | ||
| 0.892452975558004 | ||
| 0.16973367306396 | ||
| 0.912292406867098 | ||
| 0.0923260018966512 | ||
| 0.216301713289429 | ||
| 0.147861410064151 | ||
| 0.8600781655845 | ||
| 0.752129792595509 | ||
| 0.337431120990153 | ||
| 0.542476014178907 | ||
| 0.307279789725491 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| from .abstract_discrete_distribution import AbstractLDDiscreteDistribution | ||
| from ..util import ParameterError | ||
| from ..abstract_discrete_distribution import AbstractLDDiscreteDistribution | ||
| from ...util import ParameterError | ||
| import numpy as np | ||
| import warnings | ||
|
|
||
|
|
@@ -243,6 +243,7 @@ def __init__(self, | |
| - `"CBC"`: uses the first $d$ components of a known good Component-by-Component (CBC) generating vector. | ||
| - `"RICHTMYER"`: uses $\boldsymbol{\alpha}_j = \sqrt{p_j} \bmod 1$, where $p_j$ are primes. This is the classical Richtmyer construction. | ||
| - `"SUZUKI"`: uses a deterministic construction $\boldsymbol{\alpha}_j = 2^{j/(d+1)}$. | ||
| - `"CBC_MT"`: uses the first $d$ components of a known good CBC generating vector obtained using the Mobius transformation method, which can be found in kronecker_search_methods.py. | ||
| - np.array: user-specified generating vector. | ||
|
|
||
| shift (np.ndarray): Shift vector $\boldsymbol{\delta}$. If `randomize=True`, this is ignored and a random shift is generated. Otherwise, a fixed shift is used. | ||
|
|
@@ -284,7 +285,118 @@ def __init__(self, | |
| gen_vec = _richtmyer_generating_vector(self.dvec.max()+1) | ||
| elif isinstance(generating_vector, str) and generating_vector.lower() == "suzuki": | ||
| self.gen_vec_source = "SUZUKI" | ||
| gen_vec = _suzuki_generating_vector(self.dvec.max()+1) | ||
| gen_vec = _suzuki_generating_vector(self.dvec.max()+1) | ||
| elif isinstance(generating_vector, str) and generating_vector.lower() == "cbc_mt": | ||
| self.gen_vec_source = "CBC_MT" | ||
| CBC_MT = np.array([0.618033988749895, | ||
| 0.3173225474723, | ||
| 0.59332263014446, | ||
| 0.20776441643926, | ||
| 0.27373719258623, | ||
| 0.649734278361753, | ||
| 0.478954018631769, | ||
| 0.86866022435182, | ||
| 0.22845082022244, | ||
| 0.581365429377986, | ||
| 0.282365231829842, | ||
| 0.0822850909119904, | ||
| 0.223849641007295, | ||
| 0.5770772201756, | ||
| 0.51769659336634, | ||
| 0.568025390904592, | ||
| 0.156782234569368, | ||
| 0.82246227056154, | ||
| 0.805675312097409, | ||
| 0.63877102813393, | ||
| 0.358300563495856, | ||
| 0.241741343018598, | ||
| 0.705003192174204, | ||
| 0.1931911954956, | ||
| 0.261022001488623, | ||
| 0.897938992038015, | ||
| 0.46839743115877, | ||
| 0.884022067965329, | ||
| 0.752352896871505, | ||
| 0.1601583600427, | ||
| 0.10727599509739, | ||
| 0.151478435512877, | ||
| 0.163863657127101, | ||
| 0.948303450359399, | ||
| 0.80350943597439, | ||
| 0.426371623468333, | ||
| 0.435930910910882, | ||
| 0.21329852459791, | ||
| 0.661698149534002, | ||
| 0.900679822160453, | ||
| 0.122436710671457, | ||
| 0.483663584095611, | ||
| 0.928181067731583, | ||
| 0.443143014606576, | ||
| 0.74491332336194, | ||
| 0.87948409225588, | ||
| 0.0428242449803, | ||
| 0.534576896789579, | ||
| 0.24340042100879, | ||
| 0.30424418245585, | ||
| 0.574003104342617, | ||
| 0.897289023268963, | ||
| 0.541424476559586, | ||
| 0.356895660350464, | ||
| 0.507567280910795, | ||
| 0.513983550428507, | ||
| 0.0610821922457415, | ||
| 0.183871471606587, | ||
| 0.446015178033969, | ||
| 0.455684287415085, | ||
| 0.280817534817491, | ||
| 0.115220095666085, | ||
| 0.433740673279323, | ||
| 0.515605957977756, | ||
| 0.113076735656464, | ||
| 0.733928297688305, | ||
| 0.0597515651584137, | ||
| 0.422268695684775, | ||
| 0.0979181139173599, | ||
| 0.213699261322352, | ||
| 0.866811679881922, | ||
| 0.0878569329036737, | ||
| 0.678412735893121, | ||
| 0.181093969536107, | ||
| 0.128913741473518, | ||
| 0.109341703717108, | ||
| 0.289067270578427, | ||
| 0.352218331663839, | ||
| 0.303605902333137, | ||
| 0.0613899204730832, | ||
| 0.959535877660851, | ||
| 0.475508309069064, | ||
| 0.688698902674194, | ||
| 0.657037932118495, | ||
| 0.645555897563869, | ||
| 0.720658665263604, | ||
| 0.914423387894897, | ||
| 0.425763295044487, | ||
| 0.328825255006553, | ||
| 0.892452975558004, | ||
| 0.16973367306396, | ||
| 0.912292406867098, | ||
| 0.0923260018966512, | ||
| 0.216301713289429, | ||
| 0.147861410064151, | ||
| 0.8600781655845, | ||
| 0.752129792595509, | ||
| 0.337431120990153, | ||
| 0.542476014178907, | ||
| 0.307279789725491], dtype=np.float64) | ||
| gen_vec = CBC_MT | ||
| if not (self.dvec.max() < len(gen_vec)): | ||
| if warn: | ||
| warnings.warn( | ||
| f"CBC_MT generating vector only supports dimension <= {len(CBC_MT)}; falling back to Richtmyer.", | ||
| RuntimeWarning, | ||
| ) | ||
| self.gen_vec_source = "RICHTMYER" | ||
| gen_vec = _richtmyer_generating_vector(self.dvec.max()+1) | ||
| else: | ||
| self.gen_vec_source = "CUSTOM" | ||
| gen_vec = np.asarray(generating_vector, dtype=float) | ||
|
|
@@ -349,7 +461,7 @@ def periodic_discrepancy(self, n, k_tilde=None, gamma=None): | |
| return np.sqrt(self._square_periodic_discrepancies(n, k_tilde, gamma)) | ||
|
|
||
|
|
||
| def wssd_discrepancy(self, n, weights, k_tilde = None, gamma = None): | ||
| def wssd_discrepancy(self, n, sample_weights, k_tilde = None, gamma = None): | ||
| # calculates the weighted sum of square discrepancy | ||
| if gamma is None: | ||
| gamma = np.ones(self.d) | ||
|
|
@@ -358,12 +470,15 @@ def wssd_discrepancy(self, n, weights, k_tilde = None, gamma = None): | |
| k_tilde = (lambda x, gamma: np.prod(1 + (x * (x - 1) + 1/6) * gamma, axis=-1), 1) | ||
|
|
||
| discrepancies = self._square_periodic_discrepancies(n, k_tilde, gamma) | ||
| return np.sum(weights * discrepancies, axis=-1) | ||
| return np.sum(sample_weights * discrepancies, axis=-1) | ||
|
|
||
|
|
||
| def _square_periodic_discrepancies(self, n, k_tilde, gamma): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe this makes more sense as a function in
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if it does or not, since it is used as a method to calculate discrepancy for any Kronecker object, as opposed to being solely focused on search methods.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's leave it here for now and we can always move it in the future |
||
| n_array = np.arange(1, n + 1) | ||
| k_tilde_terms = k_tilde[0](self.gen_samples(n=n), gamma) | ||
| # we need the points without a random shift for the calculation, so we can't use self._gen_samples | ||
| i = np.arange(0, n) | ||
| points = (i[:,None] * self.gen_vec[:,None,:]) % 1 | ||
| k_tilde_terms = k_tilde[0](points, gamma) | ||
|
|
||
| left_sum = np.cumsum(k_tilde_terms[...,1:], axis=-1) * n_array[1:] | ||
| right_sum = np.cumsum(n_array[:-1] * k_tilde_terms[...,1:], axis=-1) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AndersPride @alegresor
Is this file available from LDData? Do we need to duplicate it here?