fix coal mining example
import pandas as pd
import keanu as kn
from examples import CoalMining
-
-
+import statistics
def test_coalmining():
coal_mining = CoalMining()
@@ -11,8 +10,7 @@ def test_coalmining():
model.disasters.observe(coal_mining.training_data())
net = kn.BayesNet(model.switchpoint.get_connected_graph())
- posterior_dist_samples = kn.MetropolisHastings().get_posterior_samples(net, net.get_latent_vertices(), 50000)
- posterior_dist_samples.drop(10000).down_sample(5)
+ samples = kn.sample(net=net, sample_from=net.get_latent_vertices(), draws=50000, drop=10000, down_sample_interval=5)
- switch_year = posterior_dist_samples.get_integer_tensor_samples(model.switchpoint).get_scalar_mode()
+ switch_year = statistics.mode([sample[0] for sample in samples[model.switchpoint.get_id()]])
assert switch_year == 1890
