Skip to content

module adabmDCA.sampling


function sampling_profile

sampling_profile(params: Dict[str, Tensor], nsamples: int, beta: float) → Tensor

Samples from the profile model defined by the local biases only.

Args:

  • params (Dict[str, torch.Tensor]): Parameters of the model. - "bias": Tensor of shape (L, q) - local biases.
  • nsamples (int): Number of samples to generate.
  • beta (float): Inverse temperature.

Returns:

  • torch.Tensor: Sampled one-hot encoded sequences of shape (nsamples, L, q).

function gibbs_step_uniform_sites

gibbs_step_uniform_sites(
    chains: Tensor,
    params: Dict[str, Tensor],
    beta: float = 1.0
) → Tensor

Performs a single mutation using the Gibbs sampler. In this version, the mutation is attempted at the same sites for all chains.

Args:

  • chains (torch.Tensor): One-hot encoded sequences of shape (batch_size, L, q).
  • params (Dict[str, torch.Tensor]): Parameters of the model. - "bias": Tensor of shape (L, q) - local biases. - "coupling_matrix": Tensor of shape (L, q, L, q) - coupling matrix.
  • beta (float, optional): Inverse temperature. Defaults to 1.0.

Returns:

  • torch.Tensor: Updated chains.

function gibbs_step_independent_sites

gibbs_step_independent_sites(
    chains: Tensor,
    params: Dict[str, Tensor],
    beta: float = 1.0
) → Tensor

Performs a single mutation using the Gibbs sampler. This version selects different random sites for each chain. It is less efficient than the 'gibbs_step_uniform_sites' function, but it is more suitable for mutating starting from the same wild-type sequence since mutations are independent across chains.

Args:

  • chains (torch.Tensor): One-hot encoded sequences of shape (batch_size, L, q).
  • params (Dict[str, torch.Tensor]): Parameters of the model. - "bias": Tensor of shape (L, q) - local biases. - "coupling_matrix": Tensor of shape (L, q, L, q) - coupling matrix.
  • beta (float, optional): Inverse temperature. Defaults to 1.0.

Returns:

  • torch.Tensor: Updated chains.

function gibbs_sampling

gibbs_sampling(
    chains: Tensor,
    params: Dict[str, Tensor],
    nsweeps: int,
    beta: float = 1.0
) → Tensor

Gibbs sampling. Attempts L * nsweeps mutations to each sequence in 'chains'.

Args:

  • chains (torch.Tensor): Initial one-hot encoded samples of size (batch_size, L, q).
  • params (Dict[str, torch.Tensor]): Parameters of the model. - "bias": Tensor of shape (L, q) - local biases. - "coupling_matrix": Tensor of shape (L, q, L, q) - coupling matrix.
  • nsweeps (int): Number of sweeps, where one sweep corresponds to attempting L mutations.
  • beta (float, optional): Inverse temperature. Defaults to 1.0.

Returns:

  • torch.Tensor: Updated chains.

function metropolis_step_uniform_sites

metropolis_step_uniform_sites(
    chains: Tensor,
    params: Dict[str, Tensor],
    beta: float = 1.0
) → Tensor

Performs a single mutation using the Metropolis sampler. In this version, the mutation is attempted at the same sites for all chains.

Args:

  • chains (torch.Tensor): One-hot encoded sequences of shape (batch_size, L, q).
  • params (Dict[str, torch.Tensor]): Parameters of the model. - "bias": Tensor of shape (L, q) - local biases. - "coupling_matrix": Tensor of shape (L, q, L, q) - coupling matrix.
  • beta (float, optional): Inverse temperature. Defaults to 1.0.

Returns:

  • torch.Tensor: Updated chains.

function metropolis_step_independent_sites

metropolis_step_independent_sites(
    chains: Tensor,
    params: Dict[str, Tensor],
    beta: float = 1.0
) → Tensor

Performs a single mutation using the Metropolis sampler. This version selects different random sites for each chain. It is less efficient than the 'metropolis_step_uniform_sites' function, but it is more suitable for mutating starting from the same wild-type sequence since mutations are independent across chains.

Args:

  • chains (torch.Tensor): One-hot encoded sequences of shape (batch_size, L, q).
  • params (Dict[str, torch.Tensor]): Parameters of the model. - "bias": Tensor of shape (L, q) - local biases. - "coupling_matrix": Tensor of shape (L, q, L, q) - coupling matrix.
  • beta (float, optional): Inverse temperature. Defaults to 1.0.

Returns:

  • torch.Tensor: Updated chains.

function metropolis_sampling

metropolis_sampling(
    chains: Tensor,
    params: Dict[str, Tensor],
    nsweeps: int,
    beta: float = 1.0
) → Tensor

Metropolis sampling. Attempts L * nsweeps mutations to each sequence in 'chains'.

Args:

  • chains (torch.Tensor): One-hot encoded sequences of shape (batch_size, L, q).
  • params (Dict[str, torch.Tensor]): Parameters of the model. - "bias": Tensor of shape (L, q) - local biases. - "coupling_matrix": Tensor of shape (L, q, L, q) - coupling matrix.
  • nsweeps (int): Number of sweeps to be performed, where one sweep corresponds to attempting L mutations.
  • beta (float, optional): Inverse temperature. Defaults to 1.0.

Returns:

  • torch.Tensor: Updated chains.

function get_sampler

get_sampler(sampling_method: str) → Callable

Returns the sampling function corresponding to the chosen method.

Args:

  • sampling_method (str): String indicating the sampling method. Choose between 'metropolis' and 'gibbs'.

Raises:

  • KeyError: Unknown sampling method.

Returns:

  • Callable: Sampling function.

This file was automatically generated via lazydocs.