Skip to content

module adabmDCA.statmech


function couplings_are_symmetric

couplings_are_symmetric(couplings: Tensor) → bool

Whether J[i, a, j, b] == J[j, b, i, a] exactly, as for every trained Potts model.

The answer is cached per tensor and recomputed after in-place changes, so kernels can ask on every call. Kernels use it to sum pair terms once.


function compute_energy

compute_energy(x: Tensor, params: Dict[str, Tensor]) → Tensor

Compute the DCA energy for a batch of sequences.

Args:

  • x (torch.Tensor): Tensor of shape (batch_size, L, q) - batch of one-hot encoded sequences.
  • 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.

Returns:

  • torch.Tensor: Tensor of shape (batch_size,) - DCA energy for each sequence in the batch.

function get_cde

get_cde(x: Tensor, params: dict[str, Tensor]) → Tensor

Compute per-site context-dependent entropy of one-hot sequences.

For each site i, hold all other residues fixed, evaluate the model probability of every state at i, and return the Shannon entropy of that conditional distribution in nats. The conditional probabilities follow the same energy convention as compute_energy, including asymmetric couplings and nonzero same-site terms.

Args:

  • x: One-hot sequence of shape (L, q) or batch of shape (N, L, q). It is moved to the model's device and dtype.
  • params: Model parameters with bias of shape (L, q) and coupling_matrix of shape (L, q, L, q).

Returns: Tensor of shape (L,) for one sequence or (N, L) for a batch.

Raises:

  • ValueError: If the parameter or sequence dimensions are incompatible, or x is not one-hot encoded.

function compute_log_likelihood

compute_log_likelihood(
    fi: Tensor,
    fij: Tensor,
    params: Dict[str, Tensor],
    logZ: float
) → float

Compute the log-likelihood per residue of the model.

Args:

  • fi (torch.Tensor): Single-site frequencies of the data.
  • fij (torch.Tensor): Two-site frequencies of the data.
  • params (Dict[str, torch.Tensor]): Parameters of the model.
  • logZ (float): Log-partition function of the model.

Returns:

  • float: Log-likelihood per residue of the model.

function enumerate_states

enumerate_states(L: int, q: int, device: device = device(type='cpu')) → Tensor

Enumerate all possible states of a system of L sites and q states.

Args:

  • L (int): Number of sites.
  • q (int): Number of states.
  • device (torch.device, optional): Device to store the states. Defaults to "cpu".

Returns:

  • torch.Tensor: All possible states.

function compute_logZ_exact

compute_logZ_exact(all_states: Tensor, params: Dict[str, Tensor]) → float

Compute the log-partition function of the model.

Args:

  • all_states (torch.Tensor): All possible states of the system.
  • params (Dict[str, torch.Tensor]): Parameters of the model.

Returns:

  • float: Log-partition function of the model.

function compute_entropy

compute_entropy(chains: Tensor, params: Dict[str, Tensor], logZ: float) → float

Compute the entropy of the DCA model.

Args:

  • chains (torch.Tensor): Chains that are supposed to be an equilibrium realization of the model.
  • params (Dict[str, torch.Tensor]): Parameters of the model.
  • logZ (float): Log-partition function of the model.

Returns:

  • float: Entropy of the model.

function exchange_log_acceptance

exchange_log_acceptance(prev_params, curr_params, prev_chains, curr_chains)

Deterministic log Metropolis acceptance for Hamiltonian exchange.


function iterate_tap

iterate_tap(
    mag: Tensor,
    params: Dict[str, Tensor],
    max_iter: int = 500,
    epsilon: float = 0.0001
) → Tensor

Iterates the TAP equations until convergence.

Args:

  • mag (torch.Tensor): Initial magnetizations.
  • params (Dict[str, torch.Tensor]): Parameters of the model.
  • max_iter (int, optional): Maximum number of iterations. Defaults to 500.
  • epsilon (float, optional): Convergence threshold. Defaults to 1e-4.

Returns:

  • torch.Tensor: Fixed point magnetizations of the TAP equations.

This file was automatically generated via lazydocs.