class_docstr: Encapsulate Pyro specific logic.
docstr: Extract log likelihood from Pyro posterior.
docstr_tok: ["Extract","log","likelihood","from","Pyro","posterior","."]
code: def log_likelihood_to_xarray(self):
      """Extract log likelihood from Pyro posterior."""
      if not self.log_likelihood:
          return None
      data = {}
      if self.observations is not None:
          try:
              samples = self.posterior.get_samples(group_by_chain=False)
              predictive = self.pyro.infer.Predictive(
                  self.model, samples
              )
              vectorized_trace = predictive.get_vectorized_trace(
                  *self._args, **self._kwargs
              )
              for obs_name in self.observations.keys():
                  obs_site = vectorized_trace.nodes[obs_name]
                  log_like = (
                      obs_site["fn"]
                      .log_prob(obs_site["value"])
                      .detach()
                      .cpu()
                      .numpy()
                  )
                  shape = (self.nchains, self.ndraws) + log_like.shape[
                      1:
                  ]
                  data[obs_name] = np.reshape(log_like, shape)
          except:  # pylint: disable=bare-except
              # cannot get vectorized trace
              warnings.warn(
                  "Could not get vectorized trace, log_likelihood group will be omitted. "
                  "Check your model vectorization or set log_likelihood=False"
              )
              return None
      return dict_to_dataset(
          data,
          library=self.pyro,
          coords=self.coords,
          dims=self.dims,
          skip_event_dims=True,
      )
  
imports: import logging
  from typing import Callable, Optional
  import warnings
  import numpy
  from packaging import version
  from ..None import utils
  from ..rcparams import rcParams
  from .base import dict_to_dataset, requires
  from .inference_data import InferenceData
label_desc: Use image node_id 4 for calling the PyroConverter obj's underlying member method code with example usage: obj.log_likelihood_to_xarray() and returns: dict_to_dataset, None, None