Skip to content
Snippets Groups Projects
Commit 6cc8428e authored by Colm Talbot's avatar Colm Talbot Committed by Moritz Huebner
Browse files

Fix constrained prior sampling

parent 5428c2ee
No related branches found
No related tags found
No related merge requests found
......@@ -365,23 +365,21 @@ class PriorDict(dict):
return sample
else:
needed = np.prod(size)
constraint_keys = list()
for ii, key in enumerate(keys[-1::-1]):
for key in keys.copy():
if isinstance(self[key], Constraint):
constraint_keys.append(-ii - 1)
for ii in constraint_keys[-1::-1]:
del keys[ii]
del keys[keys.index(key)]
all_samples = {key: np.array([]) for key in keys}
_first_key = list(all_samples.keys())[0]
while len(all_samples[_first_key]) < needed:
samples = self.sample_subset(keys=keys, size=needed)
keep = np.array(self.evaluate_constraints(samples), dtype=bool)
for key in samples:
all_samples[key] = np.hstack(
[all_samples[key], samples[key][keep].flatten()])
all_samples = {key: np.reshape(all_samples[key][:needed], size)
for key in all_samples
if not isinstance(self[key], Constraint)}
for key in keys:
all_samples[key] = np.hstack([
all_samples[key], samples[key][keep].flatten()
])
all_samples = {
key: np.reshape(all_samples[key][:needed], size) for key in keys
}
return all_samples
def normalize_constraint_factor(self, keys):
......
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