コード例 #1
0
 def test_draw_gaussian_samples(self):
     """ Tests for draw gaussian samples. """
     self.report(
         'draw_gaussian_samples. Probabilistic test, could fail at times')
     num_samples = 10000
     num_pts = 3
     mu = list(range(num_pts))
     K = np.random.normal(size=(num_pts, num_pts))
     K = K.dot(K.T)
     samples = general_utils.draw_gaussian_samples(num_samples, mu, K)
     sample_mean = samples.mean(axis=0)
     sample_centralised = samples - sample_mean
     sample_covar = sample_centralised.T.dot(
         sample_centralised) / num_samples
     mean_tol = 4 * np.linalg.norm(mu) / np.sqrt(num_samples)
     covar_tol = 4 * np.linalg.norm(K) / np.sqrt(num_samples)
     mean_err = np.linalg.norm(mu - sample_mean)
     covar_err = np.linalg.norm(K - sample_covar)
     self.report(
         'Mean error (tol): ' + str(mean_err) + ' (' + str(mean_tol) + ')',
         'test_result')
     self.report(
         'Cov error (tol): ' + str(covar_err) + ' (' + str(covar_tol) + ')',
         'test_result')
     assert mean_err < mean_tol
     assert covar_err < covar_tol
コード例 #2
0
 def draw_samples(self,
                  num_samples,
                  X_test=None,
                  mean_vals=None,
                  covar=None):
     """ Draws num_samples samples at returns their values at X_test. """
     if X_test is not None:
         mean_vals, covar = self.eval(X_test, 'covar')
     return draw_gaussian_samples(num_samples, mean_vals, covar)
コード例 #3
0
 def draw_samples_with_hallucinated_observations(self, num_samples, X_test,
                                                 X_halluc):
   """ Draws samples with hallucinated observations. """
   mean_vals, aug_covar = self.eval_with_hallucinated_observations(X_test,
                        X_halluc, uncert_form='covar')
   return draw_gaussian_samples(num_samples, mean_vals, aug_covar)