original_docstring: Evaluate elbo and average per residue perplexity.
docstring: Evaluate elbo and average per residue perplexity.
docstring_tokens: Evaluate elbo and average per residue perplexity .
code: def _evaluate_local_elbo(self, svi, dataload, data_size):
          """Evaluate elbo and average per residue perplexity."""
          lp, perplex = 0.0, 0.0
          with torch.no_grad():
              for seq_data, L_data in dataload:
                  if self.is_cuda:
                      seq_data, L_data = seq_data.cuda(), L_data.cuda()
                  conditioned_model = poutine.condition(
                      self.model, data={"obs_seq": seq_data}
                  )
                  args = (seq_data, torch.tensor(1.0))
                  guide_tr = poutine.trace(self.guide).get_trace(*args)
                  model_tr = poutine.trace(
                      poutine.replay(conditioned_model, trace=guide_tr)
                  ).get_trace(*args)
                  local_elbo = (
                      (
                          model_tr.log_prob_sum(self._local_variables)
                          - guide_tr.log_prob_sum(self._local_variables)
                      )
                      .cpu()
                      .numpy()
                  )
                  lp += local_elbo
                  perplex += -local_elbo / L_data[0].cpu().numpy()
          perplex = np.exp(perplex / data_size)
          return lp, perplex
code_tokens: def _evaluate_local_elbo ( self , svi , dataload , data_size ) : lp , perplex = 0.0 , 0.0 with torch . no_grad ( ) : for seq_data , L_data in dataload : if self . is_cuda : seq_data , L_data = seq_data . cuda ( ) , L_data . cuda ( ) conditioned_model = poutine . condition ( self . model , data = { "obs_seq" : seq_data } ) args = ( seq_data , torch . tensor ( 1.0 ) ) guide_tr = poutine . trace ( self . guide ) . get_trace ( * args ) model_tr = poutine . trace ( poutine . replay ( conditioned_model , trace = guide_tr ) ) . get_trace ( * args ) local_elbo = ( ( model_tr . log_prob_sum ( self . _local_variables ) - guide_tr . log_prob_sum ( self . _local_variables ) ) . cpu ( ) . numpy ( ) ) lp += local_elbo perplex += - local_elbo / L_data [ 0 ] . cpu ( ) . numpy ( ) perplex = np . exp ( perplex / data_size ) return lp , perplex
short_docstring: Evaluate elbo and average per residue perplexity.
short_docstring_tokens: Evaluate elbo and average per residue perplexity .
comment: """Evaluate elbo and average per residue perplexity."""