Skip to content

Commit

Permalink
Fix bug in LinearGaussianCPD and fix failing test in test_continuous_…
Browse files Browse the repository at this point in the history
…sampling
  • Loading branch information
grotmol committed Aug 3, 2017
1 parent bfe1da0 commit 06b1662
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions pgmpy/factors/continuous/LinearGaussianCPD.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def __init__(self, variable, beta, variance, evidence=[]):
self.beta_vector = np.asarray(beta[1:])

variables = [variable] + evidence
self.variables = variables
super(LinearGaussianCPD, self).__init__(variables, pdf='gaussian',
mean=self.beta_vector,
covariance=self.variance)
Expand Down
10 changes: 9 additions & 1 deletion pgmpy/tests/test_sampling/test_continuous_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,17 @@ def test_sampling(self):
sample_covariance = np.cov(samples_array.T)
self.assertTrue(np.linalg.norm(sample_covariance - self.test_model.covariance) < 3)

np.random.seed(12313131)
# np.random.seed(12313131)
np.random.seed(1231313)
samples = self.nuts_sampler.sample(initial_pos=[0.2, 0.4, 2.2], num_adapt=10000, num_samples=10000)
sample_covariance = np.cov(samples.values.T)
norm_of_covariance_difference = np.linalg.norm(sample_covariance - self.test_model.covariance)
if norm_of_covariance_difference >= 0.4:
print("Failing test - the norm is %f, but should be < 0.4" % (norm_of_covariance_difference, ))
print("Correct covariance:")
print(self.test_model.covariance)
print("Sampled covariance:")
print(sample_covariance)
self.assertTrue(np.linalg.norm(sample_covariance - self.test_model.covariance) < 0.4)

np.random.seed(921312312)
Expand Down

0 comments on commit 06b1662

Please sign in to comment.