Skip to content
Snippets Groups Projects
Commit 4ca86425 authored by Moritz Huebner's avatar Moritz Huebner
Browse files

Merge branch 'constrained-prior-sampling' into 'master'

Fix constrained prior sampling

See merge request !863
parents b0bf2f37 6cc8428e
No related branches found
No related tags found
1 merge request!863Fix constrained prior sampling
Pipeline #152987 failed
......@@ -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