class_docstr: ## Sampler class
class_docstr_tok: ["#","#","Sampler","class"]
docstr: #### Interpolate two images $x_0$ and $x'_0$
  
  We get $x_t \sim q(x_t|x_0)$ and $x'_t \sim q(x'_t|x_0)$.
  
  Then interpolate to
   $$ar{x}_t = (1 - \lambda)x_t + \lambda x'_0$$
  
  Then get
   $$ar{x}_0 \sim        extcolor{lightgreen}{p_ heta}(x_0|ar{x}_t)$$
  
  * `x1` is $x_0$
  * `x2` is $x'_0$
  * `lambda_` is $\lambda$
  * `t_` is $t$
docstr_tok: ["#","#","#","#","Interpolate","two","images","$","x_0","$","and","$","x'_0","$","We","get","$","x_t","\\sim","q","(","x_t|x_0",")","$","and","$","x'_t","\\sim","q","(","x'_t|x_0",")","$",".","Then","interpolate","to","$","$","\bar","{","x","}","_t","=","(","1","-","\\lambda",")","x_t","+","\\lambda","x'_0","$","$","Then","get","$","$","\bar","{","x","}","_0","\\sim","extcolor","{","lightgreen","}","{","p_","heta","}","(","x_0|\bar","{","x","}","_t",")","$","$","*","`","x1","`","is","$","x_0","$","*","`","x2","`","is","$","x'_0","$","*","`","lambda_","`","is","$","\\lambda","$","*","`","t_","`","is","$","t","$"]
code: def interpolate(
      self,
      x1: torch.Tensor,
      x2: torch.Tensor,
      lambda_: float,
      t_: int = 100,
  ):
      """
      #### Interpolate two images $x_0$ and $x'_0$
  
      We get $x_t \sim q(x_t|x_0)$ and $x'_t \sim q(x'_t|x_0)$.
  
      Then interpolate to
       $$\bar{x}_t = (1 - \lambda)x_t + \lambda x'_0$$
  
      Then get
       $$\bar{x}_0 \sim \textcolor{lightgreen}{p_\theta}(x_0|\bar{x}_t)$$
  
      * `x1` is $x_0$
      * `x2` is $x'_0$
      * `lambda_` is $\lambda$
      * `t_` is $t$
      """
  
      # Number of samples
      n_samples = x1.shape[0]
      # $t$ tensor
      t = torch.full((n_samples,), t_, device=self.device)
      # $$\bar{x}_t = (1 - \lambda)x_t + \lambda x'_0$$
      xt = (1 - lambda_) * self.diffusion.q_sample(
          x1, t
      ) + lambda_ * self.diffusion.q_sample(x2, t)
  
      # $$\bar{x}_0 \sim \textcolor{lightgreen}{p_\theta}(x_0|\bar{x}_t)$$
      return self._sample_x0(xt, t_)
  
file_path: annotated_deep_learning_paper_implementations/labml_nn/diffusion/ddpm/evaluate.py
imports: import numpy
  import torch
  from matplotlib import pyplot
  from torchvision.transforms.functional import to_pil_image, resize
  from labml import experiment, monit
  from labml_nn.diffusion.ddpm import DenoiseDiffusion, gather
  from labml_nn.diffusion.ddpm.experiment import Configs
label_desc: Use image node_id 5 for calling the Sampler obj's underlying member method code with example usage: obj.interpolate(x1, x2, lambda_, t_) and returns: self