Closed munichpavel closed 4 years ago
Even more obvious that ancestral sampling is wrong:
# X0, X1 independent
X0 = BayesianNodeRV('X0', np.array([0.5, 0.5]))
X1 = BayesianNodeRV('X1', np.array([0.5, 0.5]))
bn = FakeDataBayesianNetwork(X0, X1)
samples = bn.rvs(size=10000, seed=42)
sample_ratios = samples.groupby(['X0', 'X1']).size() / samples.shape[0]
expected_index = pd.MultiIndex.from_tuples(
[(0,0), (0,1), (1,0), (1,1)],
names=['X0', 'X1'])
expected_ratios = pd.Series(
[0.25, 0.25, 0.25, 0.25],
index=expected_index
)
pd.testing.assert_series_equal(
sample_ratios, expected_ratios,
check_exact=False, check_less_precise=4
)
Error message:
E AssertionError: Series are different
E
E Series length are different
E [left]: 2, MultiIndex([(0, 0),
E (1, 1)],
E names=['X0', 'X1'])
E [right]: 4, MultiIndex([(0, 0),
E (0, 1),
E (1, 0),
E (1, 1)],
E names=['X0', 'X1'])
So the outcomes (0,1) and (1,0) do not appear in ancestral sampling.
The issue was with setting the seeds, as in #12. Decided to just drop this feature as it had caused more trouble than it was worth.
Failing test: