Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_sample_object_to_dict():
data_rej = OrderedDict()
data_smc = OrderedDict()
m = get_model(n_obs=100, true_params=[.6, .2])
batch_size, n = 1, 2
schedule = [0.7, 0.2, 0.05]
rej = elfi.Rejection(m['d'], batch_size=batch_size)
res_rej = rej.sample(n, threshold=0.1)
smc = elfi.SMC(m['d'], batch_size=batch_size)
res_smc = smc.sample(n, schedule)
sample_object_to_dict(data_rej, res_rej)
sample_object_to_dict(data_smc, res_smc, skip='populations')
assert any(x not in data_rej for x in ['meta', 'output']) is True
assert any(x not in data_smc for x in ['meta', 'output', 'populations']) is True
def test_multi_parameter_linear_adjustment():
"""A regression test against values obtained in the notebook."""
seed = 20170511
threshold = 0.2
batch_size = 1000
n_samples = 500
m = ma2.get_model(true_params=[0.6, 0.2], seed_obs=seed)
summary_names = ['S1', 'S2']
parameter_names = ['t1', 't2']
linear_adjustment = LinearAdjustment()
res = elfi.Rejection(
m['d'],
batch_size=batch_size,
output_names=['S1', 'S2'],
# output_names=summary_names, # fails ?!?!?
seed=seed).sample(
n_samples, threshold=threshold)
adjusted = adjust_posterior(
model=m,
sample=res,
parameter_names=parameter_names,
import elfi
from elfi.examples import ma2
# load the model from elfi.examples
model = ma2.get_model()
# setup and run rejection sampling
rej = elfi.Rejection(model['d'], batch_size=10000)
result = rej.sample(1000, quantile=0.01)
# show summary of results on stdout
result.summary()