class_docstr: Forecaster for a :class:`ForecastingModel` using variational inference.
  
  On initialization, this fits a distribution using variational inference
  over latent variables and exact inference over the noise distribution,
  typically a :class:`~pyro.distributions.GaussianHMM` or variant.
  
  After construction this can be called to generate sample forecasts.
  
  :ivar list losses: A list of losses recorded during training, typically
      used to debug convergence. Defined by ``loss = -elbo / data.numel()``.
  
  :param ForecastingModel model: A forecasting model subclass instance.
  :param data: A tensor dataset with time dimension -2.
  :type data: ~torch.Tensor
  :param covariates: A tensor of covariates with time dimension -2.
      For models not using covariates, pass a shaped empty tensor
      ``torch.empty(duration, 0)``.
  :type covariates: ~torch.Tensor
  
  :param guide: Optional guide instance. Defaults to a
      :class:`~pyro.infer.autoguide.AutoNormal`.
  :type guide: ~pyro.nn.module.PyroModule
  :param callable init_loc_fn: A per-site initialization function for the
      :class:`~pyro.infer.autoguide.AutoNormal` guide. Defaults to
      :func:`~pyro.infer.autoguide.initialization.init_to_sample`. See
      :ref:`autoguide-initialization` section for available functions.
  :param float init_scale: Initial uncertainty scale of the
      :class:`~pyro.infer.autoguide.AutoNormal` guide.
  :param callable create_plates: An optional function to create plates for
      subsampling with the :class:`~pyro.infer.autoguide.AutoNormal` guide.
  :param optim: An optional Pyro optimizer. Defaults to a freshly constructed
      :class:`~pyro.optim.optim.DCTAdam`.
  :type optim: ~pyro.optim.optim.PyroOptim
  :param float learning_rate: Learning rate used by
      :class:`~pyro.optim.optim.DCTAdam`.
  :param tuple betas: Coefficients for running averages used by
      :class:`~pyro.optim.optim.DCTAdam`.
  :param float learning_rate_decay: Learning rate decay used by
      :class:`~pyro.optim.optim.DCTAdam`. Note this is the total decay
      over all ``num_steps``, not the per-step decay factor.
  :param float clip_norm: Norm used for gradient clipping during
      optimization. Defaults to 10.0.
  :param str time_reparam: If not None (default), reparameterize all
      time-dependent variables via the Haar wavelet transform (if "haar") or
      the discrete cosine transform (if "dct").
  :param bool dct_gradients: Whether to discrete cosine transform gradients
      in :class:`~pyro.optim.optim.DCTAdam`. Defaults to False.
  :param bool subsample_aware: whether to update gradient statistics only
      for those elements that appear in a subsample. This is used
      by :class:`~pyro.optim.optim.DCTAdam`.
  :param int num_steps: Number of :class:`~pyro.infer.svi.SVI` steps.
  :param int num_particles: Number of particles used to compute the
      :class:`~pyro.infer.elbo.ELBO`.
  :param bool vectorize_particles: If ``num_particles > 1``, determines
      whether to vectorize computation of the :class:`~pyro.infer.elbo.ELBO`.
      Defaults to True. Set to False for models with dynamic control flow.
  :param bool warm_start: Whether to warm start parameters from a smaller
      time window. Note this may introduce statistical leakage; usage is
      recommended for model exploration purposes only and should be disabled
      when publishing metrics.
  :param int log_every: Number of training steps between logging messages.
class_docstr_tok: ["Forecaster","for","a",":","class",":","`","ForecastingModel","`","using","variational","inference",".","On","initialization",",","this","fits","a","distribution","using","variational","inference","over","latent","variables","and","exact","inference","over","the","noise","distribution",",","typically","a",":","class",":","`","~pyro.distributions.GaussianHMM","`","or","variant",".","After","construction","this","can","be","called","to","generate","sample","forecasts",".",":","ivar","list","losses",":","A","list","of","losses","recorded","during","training",",","typically","used","to","debug","convergence",".","Defined","by","``","loss","=","-elbo","\/","data.numel","(",")","``",".",":","param","ForecastingModel","model",":","A","forecasting","model","subclass","instance",".",":","param","data",":","A","tensor","dataset","with","time","dimension","-2.",":","type","data",":","~torch.Tensor",":","param","covariates",":","A","tensor","of","covariates","with","time","dimension","-2",".","For","models","not","using","covariates",",","pass","a","shaped","empty","tensor","``","torch.empty","(","duration",",","0",")","``",".",":","type","covariates",":","~torch.Tensor",":","param","guide",":","Optional","guide","instance",".","Defaults","to","a",":","class",":","`","~pyro.infer.autoguide.AutoNormal","`",".",":","type","guide",":","~pyro.nn.module.PyroModule",":","param","callable","init_loc_fn",":","A","per-site","initialization","function","for","the",":","class",":","`","~pyro.infer.autoguide.AutoNormal","`","guide",".","Defaults","to",":","func",":","`","~pyro.infer.autoguide.initialization.init_to_sample","`",".","See",":","ref",":","`","autoguide-initialization","`","section","for","available","functions",".",":","param","float","init_scale",":","Initial","uncertainty","scale","of","the",":","class",":","`","~pyro.infer.autoguide.AutoNormal","`","guide",".",":","param","callable","create_plates",":","An","optional","function","to","create","plates","for","subsampling","with","the",":","class",":","`","~pyro.infer.autoguide.AutoNormal","`","guide",".",":","param","optim",":","An","optional","Pyro","optimizer",".","Defaults","to","a","freshly","constructed",":","class",":","`","~pyro.optim.optim.DCTAdam","`",".",":","type","optim",":","~pyro.optim.optim.PyroOptim",":","param","float","learning_rate",":","Learning","rate","used","by",":","class",":","`","~pyro.optim.optim.DCTAdam","`",".",":","param","tuple","betas",":","Coefficients","for","running","averages","used","by",":","class",":","`","~pyro.optim.optim.DCTAdam","`",".",":","param","float","learning_rate_decay",":","Learning","rate","decay","used","by",":","class",":","`","~pyro.optim.optim.DCTAdam","`",".","Note","this","is","the","total","decay","over","all","``","num_steps","``",",","not","the","per-step","decay","factor",".",":","param","float","clip_norm",":","Norm","used","for","gradient","clipping","during","optimization",".","Defaults","to","10.0.",":","param","str","time_reparam",":","If","not","None","(","default",")",",","reparameterize","all","time-dependent","variables","via","the","Haar","wavelet","transform","(","if","``","haar","''",")","or","the","discrete","cosine","transform","(","if","``","dct","''",")",".",":","param","bool","dct_gradients",":","Whether","to","discrete","cosine","transform","gradients","in",":","class",":","`","~pyro.optim.optim.DCTAdam","`",".","Defaults","to","False",".",":","param","bool","subsample_aware",":","whether","to","update","gradient","statistics","only","for","those","elements","that","appear","in","a","subsample",".","This","is","used","by",":","class",":","`","~pyro.optim.optim.DCTAdam","`",".",":","param","int","num_steps",":","Number","of",":","class",":","`","~pyro.infer.svi.SVI","`","steps",".",":","param","int","num_particles",":","Number","of","particles","used","to","compute","the",":","class",":","`","~pyro.infer.elbo.ELBO","`",".",":","param","bool","vectorize_particles",":","If","``","num_particles",">","1","``",",","determines","whether","to","vectorize","computation","of","the",":","class",":","`","~pyro.infer.elbo.ELBO","`",".","Defaults","to","True",".","Set","to","False","for","models","with","dynamic","control","flow",".",":","param","bool","warm_start",":","Whether","to","warm","start","parameters","from","a","smaller","time","window",".","Note","this","may","introduce","statistical","leakage",";","usage","is","recommended","for","model","exploration","purposes","only","and","should","be","disabled","when","publishing","metrics",".",":","param","int","log_every",":","Number","of","training","steps","between","logging","messages","."]
docstr: Samples forecasted values of data for time steps in ``[t1,t2)``, where
  ``t1 = data.size(-2)`` is the duration of observed data and ``t2 =
  covariates.size(-2)`` is the extended duration of covariates. For
  example to forecast 7 days forward conditioned on 30 days of
  observations, set ``t1=30`` and ``t2=37``.
  
  :param data: A tensor dataset with time dimension -2.
  :type data: ~torch.Tensor
  :param covariates: A tensor of covariates with time dimension -2.
      For models not using covariates, pass a shaped empty tensor
      ``torch.empty(duration, 0)``.
  :type covariates: ~torch.Tensor
  :param int num_samples: The number of samples to generate.
  :param int batch_size: Optional batch size for sampling. This is useful
      for generating many samples from models with large memory
      footprint. Defaults to ``num_samples``.
  :returns: A batch of joint posterior samples of shape
      ``(num_samples,1,...,1) + data.shape[:-2] + (t2-t1,data.size(-1))``,
      where the ``1``'s are inserted to avoid conflict with model plates.
  :rtype: ~torch.Tensor
docstr_tok: ["Samples","forecasted","values","of","data","for","time","steps","in","``","[","t1",",","t2",")","``",",","where","``","t1","=","data.size","(","-2",")","``","is","the","duration","of","observed","data","and","``","t2","=","covariates.size","(","-2",")","``","is","the","extended","duration","of","covariates",".","For","example","to","forecast","7","days","forward","conditioned","on","30","days","of","observations",",","set","``","t1=30","``","and","``","t2=37","``",".",":","param","data",":","A","tensor","dataset","with","time","dimension","-2.",":","type","data",":","~torch.Tensor",":","param","covariates",":","A","tensor","of","covariates","with","time","dimension","-2",".","For","models","not","using","covariates",",","pass","a","shaped","empty","tensor","``","torch.empty","(","duration",",","0",")","``",".",":","type","covariates",":","~torch.Tensor",":","param","int","num_samples",":","The","number","of","samples","to","generate",".",":","param","int","batch_size",":","Optional","batch","size","for","sampling",".","This","is","useful","for","generating","many","samples","from","models","with","large","memory","footprint",".","Defaults","to","``","num_samples","``",".",":","returns",":","A","batch","of","joint","posterior","samples","of","shape","``","(","num_samples,1",",","...",",1",")","+","data.shape","[",":","-2","]","+","(","t2-t1",",","data.size","(","-1",")",")","``",",","where","the","``","1","``","'s","are","inserted","to","avoid","conflict","with","model","plates",".",":","rtype",":","~torch.Tensor"]
code: def __call__(self, data, covariates, num_samples, batch_size=None):
      """
      Samples forecasted values of data for time steps in ``[t1,t2)``, where
      ``t1 = data.size(-2)`` is the duration of observed data and ``t2 =
      covariates.size(-2)`` is the extended duration of covariates. For
      example to forecast 7 days forward conditioned on 30 days of
      observations, set ``t1=30`` and ``t2=37``.
  
      :param data: A tensor dataset with time dimension -2.
      :type data: ~torch.Tensor
      :param covariates: A tensor of covariates with time dimension -2.
          For models not using covariates, pass a shaped empty tensor
          ``torch.empty(duration, 0)``.
      :type covariates: ~torch.Tensor
      :param int num_samples: The number of samples to generate.
      :param int batch_size: Optional batch size for sampling. This is useful
          for generating many samples from models with large memory
          footprint. Defaults to ``num_samples``.
      :returns: A batch of joint posterior samples of shape
          ``(num_samples,1,...,1) + data.shape[:-2] + (t2-t1,data.size(-1))``,
          where the ``1``'s are inserted to avoid conflict with model plates.
      :rtype: ~torch.Tensor
      """
      return super().__call__(data, covariates, num_samples, batch_size)
  
imports: import logging
  from abc import ABCMeta, abstractmethod
  from contextlib import ExitStack
  import torch
  import torch.nn
  import pyro
  import pyro.distributions
  import pyro.poutine
  from pyro.infer import MCMC, NUTS, SVI, Trace_ELBO
  from pyro.infer.autoguide import AutoNormal, init_to_sample
  from pyro.infer.predictive import _guess_max_plate_nesting
  from pyro.nn.module import PyroModule
  from pyro.optim import DCTAdam
  from .util import MarkDCTParamMessenger, PrefixConditionMessenger, PrefixReplayMessenger, PrefixWarmStartMessenger, reshape_batch, time_reparam_dct, time_reparam_haar
label_desc: Use image node_id 2 for calling the Forecaster obj's underlying member method code with example usage: obj.__call__(data, covariates, num_samples, batch_size) and returns: super