fix sampling
-from keanu.algorithm import sample
+from keanu.algorithm import sample, MetropolisHastingsSampler, HamiltonianSampler, NUTSSampler
from keanu import BayesNet, KeanuRandom, Model
from keanu.vertex import Gamma, Exponential, Cauchy, Gaussian
import numpy as np
@@ -13,8 +13,9 @@ def inference_example_metropolis():
m.a.set_value(20.)
m.b.set_value(20.)
bayes_net = m.to_bayes_net()
+ algo = MetropolisHastingsSampler()
posterior_samples = sample(net=bayes_net, sample_from=bayes_net.get_latent_vertices(),
- algo="metropolis", draws=100000)
+ sampling_algorithm=algo, draws=100000)
average_posterior_a = np.average(posterior_samples.get('a'))
average_posterior_b = np.average(posterior_samples.get('b'))
@@ -32,10 +33,15 @@ def inference_example_hmc_nuts():
m.b.set_value(20.)
bayes_net = m.to_bayes_net()
# %%SNIPPET_START%% PythonHamiltonianExample
+ algo = HamiltonianSampler()
posterior_samples = sample(net=bayes_net, sample_from=bayes_net.get_latent_vertices(),
- algo="hamiltonian", draws=2000)
+ sampling_algorithm=algo, draws=2000)
# %%SNIPPET_END%% PythonHamiltonianExample
# %%SNIPPET_START%% PythonNUTSExample
+ algo = NUTSSampler()
posterior_samples = sample(net=bayes_net, sample_from=bayes_net.get_latent_vertices(),
- algo="NUTS", draws=2000)
+ sampling_algorithm=algo, draws=2000)
# %%SNIPPET_END%% PythonNUTSExample
+
+inference_example_metropolis()
+inference_example_hmc_nuts()
