Skip to content
Snippets Groups Projects
Commit debf73ee authored by Bruce Edelman's avatar Bruce Edelman
Browse files

made PriorDict hashable and fixed caching

parent 8d340cc2
No related branches found
No related tags found
1 merge request!704Resolve #430 (Add normalisation flag to constrained prior)
......@@ -381,15 +381,20 @@ class PriorDict(dict):
@lru_cache()
def normalize_constraint_factor(self, keys):
min_accept = 50
sampling_chunk = 250
min_accept = 1000
sampling_chunk = 5000
samples = self.sample_subset(keys=keys, size=sampling_chunk)
keep = np.array(self.evaluate_constraints(samples))
keep = np.atleast_1d(self.evaluate_constraints(samples))
if len(keep) == 1:
return 1
all_samples = {key: np.array([]) for key in keys}
_first_key = list(all_samples.keys())[0]
while np.count_nonzero(keep) < min_accept:
new_samples = self.sample_subset(keys=keys, size=sampling_chunk)
samples = self.sample_subset(keys=keys, size=sampling_chunk)
for key in samples:
samples[key] = np.hstack([samples[key], new_samples[key]])
keep = np.array(self.evaluate_constraints(samples))
all_samples[key] = np.hstack(
[all_samples[key], samples[key].flatten()])
keep = np.array(self.evaluate_constraints(all_samples), dtype=bool)
return len(keep) / np.count_nonzero(keep)
def prob(self, sample, **kwargs):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment