code: def test_bayesian_linreg(self):
      print()
      logger.info("test_bayesian_linreg\n" + "-" * 80 + "\n")
      n, sigma = 100000, 1.5
      m, b = np.random.randn(2)
      t = np.linspace(0, 2, 2 * n + 1)
      x = UnivariateTimeSeries.from_pd(
          m * t + b + np.random.randn(len(t)) * sigma, name="test"
      ).to_ts()
      x_train = x[: n + 1]
      x_test = x[n + 1 :]
  
      # Make sure univariate & multivariate agree when initialized from nothing
      uni = BayesianLinReg()
      uni_posterior, uni = uni.posterior(x_train, return_updated=True)
      multi = BayesianMVLinReg()
      multi_posterior, multi = multi.posterior(
          x_train, return_updated=True
      )
      self.assertAlmostEqual(
          np.abs(uni_posterior - multi_posterior).max(), 0, places=6
      )
  
      # Get forecasts for the test split. Make sure that the stderr-normalized MSE is close to 1.
      xhat_u, sigma_u = uni.forecast(x_test.time_stamps)
      zscore_u = (
          xhat_u.to_pd() - x_test.to_pd()
      ) / sigma_u.to_pd().values
      self.assertAlmostEqual(
          zscore_u.pow(2).mean().item(), 1, delta=0.01
      )
  
      # Validate the multivariate forecasting capability as well.
      xhat_m, sigma_m = multi.forecast(x_test.time_stamps)
      zscore_m = (
          xhat_m.to_pd() - x_test.to_pd()
      ) / sigma_m.to_pd().values
      self.assertAlmostEqual(
          zscore_m.pow(2).mean().item(), 1, delta=0.01
      )
  
      # Make sure univariate & multivariate agree after an additional update
      uni_posterior = uni.posterior(x_test)
      multi_posterior = multi.posterior(x_test)
      self.assertAlmostEqual(
          np.abs(uni_posterior - multi_posterior).max(), 0, places=6
      )
  
      # Make sure explicit version agrees with naive version (univariate)
      naive_uni = np.concatenate(
          [uni.posterior(x_test[i : i + 1]) for i in range(100)]
      )
      explicit_uni = np.concatenate(
          [
              uni.posterior_explicit(x_test[i : i + 1])
              for i in range(100)
          ]
      )
      self.assertAlmostEqual(
          np.abs(naive_uni - explicit_uni).max(), 0, places=6
      )
  
      # Make sure explicit version agrees with naive version (multivariate)
      naive_multi = np.concatenate(
          [multi.posterior(x_test[i : i + 1]) for i in range(100)]
      )
      explicit_multi = np.concatenate(
          [
              multi.posterior_explicit(x_test[i : i + 1])
              for i in range(100)
          ]
      )
      self.assertAlmostEqual(
          np.abs(naive_multi - explicit_multi).max(), 0, places=6
      )
  
      # Make sure we're accurately estimating the slope & intercept
      mhat, bhat = uni.w_0
      self.assertAlmostEqual(mhat, m, delta=0.02)
      self.assertAlmostEqual(bhat, b, delta=0.01)
  
file_path: merlion/tests/change_point/test_conj_prior.py
imports: import logging
  from packaging import version
  import sys
  import unittest
  import numpy
  import scipy
  from merlion.utils.conj_priors import BetaBernoulli, NormInvGamma, MVNormInvWishart, BayesianLinReg, BayesianMVLinReg
  from merlion.utils.time_series import TimeSeries, UnivariateTimeSeries
label_desc: Use image node_id 5 for calling the TestConjugatePriors obj's underlying member method code with example usage: obj.test_bayesian_linreg() without return types