class_docstr: Utility class to track the posterior beam in the dynamic programming for BOCPD.
class_docstr_tok: ["Utility","class","to","track","the","posterior","beam","in","the","dynamic","programming","for","BOCPD","."]
code: def update(self, x):
      # self.logp starts as log P(r_{t-1} = self.run_length, x_{1:t-1})
      n = 1 if isinstance(x, tuple) and len(x) == 2 else len(x)
      # logp_x is log P(x_t)
      if n == 1:
          method = getattr(
              self.posterior,
              "posterior_explicit",
              self.posterior.posterior,
          )
      else:
          method = self.posterior.posterior
      logp_x, updated = method(x, log=True, return_updated=True)
      self.posterior = updated
      self.run_length += n
      # P(r_t = self.run_length + 1, x_{1:t}) = P(r_{t-1} = self.run_length, x_{1:t-1}) * P(x_t) * (1 - self.cp_prior)
      self.logp += sum(logp_x) + n * np.log1p(-self.cp_prior)
  
imports: import bisect
  import copy
  from enum import Enum
  import logging
  from typing import List, Tuple, Union
  import warnings
  import numpy
  import pandas
  import scipy.sparse
  from scipy.special import logsumexp
  from scipy.stats import norm
  from tqdm import tqdm
  from merlion.models.anomaly.base import NoCalibrationDetectorConfig, DetectorBase
  from merlion.models.anomaly.forecast_based.base import ForecastingDetectorBase
  from merlion.models.forecast.base import ForecasterConfig
  from merlion.plot import Figure
  from merlion.post_process.threshold import AggregateAlarms
  from merlion.utils.conj_priors import ConjPrior, MVNormInvWishart, BayesianMVLinReg
  from merlion.utils.time_series import TimeSeries, UnivariateTimeSeries, to_pd_datetime
label_desc: Use image node_id 2 for calling the _PosteriorBeam obj's underlying member method code with example usage: obj.update(x) without return types