Further tensorify test_coal_mining
@@ -13,16 +13,12 @@ def test_coalmining():
m.early_rate = kn.Exponential(np.array([[1.0, 1.0], [1.0, 1.0]]))
m.late_rate = kn.Exponential(1.0)
- m.rates = [
- kn.DoubleIf([1, 1], m.switchpoint > year, m.early_rate, m.late_rate)
- for year in range(start_year, end_year + 1)
- ]
- m.disasters = [kn.Poisson(kn.CastDouble(rate)) for rate in m.rates]
+ m.year = np.array(range(start_year, end_year + 1))
+ m.rates = kn.DoubleIf([1, 1], m.switchpoint > m.year, m.early_rate, m.late_rate)
+ m.disasters = kn.Poisson(m.rates)
- for i, disaster in enumerate(m.disasters):
- year = start_year + i
- value = data.loc[year][0]
- disaster.observe(value)
+ value = data[data.index.isin(m.year)]
+ m.disasters.observe(value.values)
net = kn.BayesNet(m.switchpoint.getConnectedGraph())
posterior_dist_samples = kn.MetropolisHastings().get_posterior_samples(net, net.getLatentVertices(), 5000)
