code: def test_weighted_covariance(ndim=10, seed=5432):
      np.random.seed(seed)
  
      L = np.random.randn(ndim, ndim)
      L[np.triu_indices_from(L, 1)] = 0.0
      L[np.diag_indices_from(L)] = np.exp(L[np.diag_indices_from(L)])
      cov = np.dot(L, L.T)
      mean = np.random.randn(ndim)
  
      samples = np.random.multivariate_normal(mean, cov, size=100)
      mu_est0 = np.mean(samples, axis=0)
      cov_est0 = np.cov(samples, rowvar=0)
  
      est = quadpotential._WeightedCovariance(ndim)
      for sample in samples:
          est.add_sample(sample)
      mu_est = est.current_mean()
      cov_est = est.current_covariance()
  
      assert np.allclose(mu_est, mu_est0)
      assert np.allclose(cov_est, cov_est0)
  
      # Make sure that the weighted estimate also works
      est2 = quadpotential._WeightedCovariance(
          ndim,
          np.mean(samples[:10], axis=0),
          np.cov(samples[:10], rowvar=0, bias=True),
          10,
      )
      for sample in samples[10:]:
          est2.add_sample(sample)
      mu_est2 = est2.current_mean()
      cov_est2 = est2.current_covariance()
  
      assert np.allclose(mu_est2, mu_est0)
      assert np.allclose(cov_est2, cov_est0)
  
imports: import warnings
  import numpy
  import numpy.testing
  import pytest
  import scipy.sparse
  import pymc
  from pymc.pytensorf import floatX
  from pymc.step_methods.hmc import quadpotential
label_desc: Use image node_id 9 for calling a global function with example usage: test_weighted_covariance(ndim, seed) without return types