class_docstr: MC Bayesian Active Learning by Disagreement
class_docstr_tok: ["MC","Bayesian","Active","Learning","by","Disagreement"]
docstr: Evaluate MC BALD on the candidate set `X`.
  
  Args:
      X: A `batch_shape x 2 x d`-dim Tensor of t-batches with `q=2`
          `d`-dim design points each.
  
  Returns:
      A `batch_shape'`-dim Tensor of MC BALD values at the given
      design points pair `X`, where `batch_shape'` is the broadcasted
      batch shape of model and input `X`.
docstr_tok: ["Evaluate","MC","BALD","on","the","candidate","set","`","X","`",".","Args",":","X",":","A","`","batch_shape","x","2","x","d","`","-dim","Tensor","of","t-batches","with","`","q=2","`","`","d","`","-dim","design","points","each",".","Returns",":","A","`","batch_shape","'","`","-dim","Tensor","of","MC","BALD","values","at","the","given","design","points","pair","`","X","`",",","where","`","batch_shape","'","`","is","the","broadcasted","batch","shape","of","model","and","input","`","X","`","."]
code: def forward(self, X: Tensor) -> Tensor:
      r"""Evaluate MC BALD on the candidate set `X`.
  
      Args:
          X: A `batch_shape x 2 x d`-dim Tensor of t-batches with `q=2`
              `d`-dim design points each.
  
      Returns:
          A `batch_shape'`-dim Tensor of MC BALD values at the given
          design points pair `X`, where `batch_shape'` is the broadcasted
          batch shape of model and input `X`.
      """
      Y = X if self.outcome_model is None else self.outcome_model(X)
  
      pref_posterior = self.model.posterior(Y)
      pref_mean = pref_posterior.mean.squeeze(-1)
      pref_cov = pref_posterior.covariance_matrix
  
      mu = pref_mean[..., 0] - pref_mean[..., 1]
      w = torch.tensor(
          [1.0, -1.0], dtype=pref_cov.dtype, device=pref_cov.device
      )
      var = 2 * self.std_noise + w @ pref_cov @ w
      sigma = torch.sqrt(var.clamp(min=SIGMA_JITTER))
  
      # eq (3) in Houlsby, et al. (2011)
      posterior_entropies = Bernoulli(
          self.std_normal.cdf(mu / torch.sqrt(var + 1))
      ).entropy()
  
      # Sample-based approx to eq (4) in Houlsby, et al. (2011)
      obj_samples = self.std_normal.cdf(
          Normal(loc=mu, scale=sigma).rsample(
              torch.Size([self.num_samples])
          )
      )
      sample_entropies = Bernoulli(obj_samples).entropy()
      conditional_entropies = sample_entropies.mean(dim=0)
  
      return posterior_entropies - conditional_entropies
  
file_path: botorch/botorch/acquisition/preference.py
imports: from __future__ import annotations
  from typing import Any, Optional
  import torch
  from botorch.acquisition import AnalyticAcquisitionFunction
  from botorch.acquisition.monte_carlo import MCAcquisitionFunction
  from botorch.exceptions.errors import UnsupportedError
  from botorch.models.deterministic import DeterministicModel
  from botorch.models.model import Model
  from botorch.utils.transforms import match_batch_shape, t_batch_mode_transform
  from torch import Tensor
  from torch.distributions import Bernoulli, Normal
label_desc: Use image node_id 2 for calling the PairwiseBayesianActiveLearningByDisagreement obj's underlying member method code with example usage: obj.forward(X) and returns: unknown