Skip to content

module adabmDCA.training

Global Variables

  • DEFAULT_INNER_GRADIENT_STEPS
  • EDGE_EMPIRICAL_PSEUDOCOUNT

function compute_gradient

compute_gradient(
    fi: Tensor,
    fij: Tensor,
    pi: Tensor,
    pij: Tensor
) → dict[str, Tensor]

Computes the gradient of the log-likelihood of the model using PyTorch.

Args:

  • fi (torch.Tensor): Single-point frequencies of the data.
  • fij (torch.Tensor): Target two-points frequencies.
  • pi (torch.Tensor): Single-point marginals of the model.
  • pij (torch.Tensor): Two-points marginals of the model.

Returns:

  • Dict[str, torch.Tensor]: Gradient.

function update_params

update_params(
    fi: Tensor,
    fij: Tensor,
    pi: Tensor,
    pij: Tensor,
    params: dict[str, Tensor],
    mask: Tensor,
    lr: float,
    l2_reg: float = 0.0
) → dict[str, Tensor]

Updates the parameters of the model.

Args:

  • fi (torch.Tensor): Single-point frequencies of the data.
  • fij (torch.Tensor): Two-points frequencies of the data.
  • pi (torch.Tensor): Single-point marginals of the model.
  • pij (torch.Tensor): Two-points marginals of the model.
  • params (Dict[str, torch.Tensor]): Parameters of the model.
  • mask (torch.Tensor): Mask of the interaction graph.
  • lr (float): Learning rate.
  • l2_reg (float, optional): L2 regularization coefficient. Defaults to 0.0.

Returns:

  • Dict[str, torch.Tensor]: Updated parameters.

function update_params_edge_activation

update_params_edge_activation(
    fij: Tensor,
    pij: Tensor,
    params: dict[str, Tensor],
    mask: Tensor
) → tuple[tuple[int, int], Tensor, dict[str, Tensor]]

Updates the mask and the coupling parameters using the edge-activation algorithm.

Args:

  • fij (torch.Tensor): Two-point frequences of the dataset.
  • pij (torch.Tensor): Two-point marginals of the model.
  • params (Dict[str, torch.Tensor]): Parameters of the model.
  • mask (torch.Tensor): Mask.

Returns:

  • torch.Tensor: Indices of the activated edge.
  • torch.Tensor: Updated mask.
  • Dict[str, torch.Tensor]: Updated parameters.

function train_graph

train_graph(
    sampler: Callable[, Tensor],
    chains: Tensor,
    mask: Tensor,
    fi_target: Tensor,
    fij_target: Tensor,
    params: dict[str, Tensor],
    nsweeps: int,
    lr: float,
    max_epochs: int,
    target_pearson: float,
    fi_val: Tensor | None = None,
    fij_val: Tensor | None = None,
    l2_reg: float = 0.0,
    controller: TrainingController | None = None
) → tuple[Tensor, dict[str, Tensor], dict[str, list[Any]]]

Trains the model on a given graph until the target Pearson correlation is reached or the maximum number of epochs is exceeded.

Args:

  • sampler (Callable): Sampling function.
  • chains (torch.Tensor): Markov chains simulated with the model.
  • mask (torch.Tensor): Mask encoding the sparse graph.
  • fi_target (torch.Tensor): Single-point frequencies of the data.
  • fij_target (torch.Tensor): Two-point frequencies of the data.
  • params (Dict[str, torch.Tensor]): Parameters of the model.
  • nsweeps (int): Number of Gibbs steps for each gradient estimation.
  • lr (float): Learning rate.
  • max_epochs (int): Maximum number of gradient updates to be done.
  • target_pearson (float): Target Pearson coefficient.
  • fi_val (Optional[torch.Tensor], optional): Single-point frequencies of the validation data. Defaults to None.
  • fij_val (Optional[torch.Tensor], optional): Two-point frequencies of the validation data. Defaults to None.
  • l2_reg (float, optional): L2 regularization coefficient. Defaults to 0.0.
  • controller (TrainingController, optional): Shared controller for counters, limits and logging.

Returns: Updated chains, parameters, and training history.


function train_eaDCA

train_eaDCA(
    sampler: Callable[, Tensor],
    fi_target: Tensor,
    fij_target: Tensor,
    params: dict[str, Tensor],
    mask: Tensor,
    chains: Tensor,
    target_pearson: float,
    nsweeps: int,
    max_epochs: int,
    pseudo_count: float,
    lr: float,
    factivate: float,
    gsteps: int,
    fi_val: Tensor | None = None,
    fij_val: Tensor | None = None,
    l2_reg: float = 0.0,
    controller: TrainingController | None = None,
    max_gradient_steps: int | None = None
) → tuple[Tensor, dict[str, Tensor], dict[str, list[Any]]]

Fits an eaDCA model on the training data and saves the results in a file.

Args:

  • sampler (Callable): Sampling function to be used.
  • fi_target (torch.Tensor): Single-point frequencies of the data.
  • fij_target (torch.Tensor): Two-point frequencies of the data.
  • params (Dict[str, torch.Tensor]): Initialization of the model's parameters.
  • mask (torch.Tensor): Initialization of the coupling matrix's mask.
  • chains (torch.Tensor): Initialization of the Markov chains.
  • target_pearson (float): Pearson correlation coefficient on the two-points statistics to be reached.
  • nsweeps (int): Number of Monte Carlo steps to update the state of the model.
  • max_epochs (int): Maximum number of epochs to be performed.
  • pseudo_count (float): Pseudo count for the single and two points statistics. Acts as a regularization.
  • lr (float): Learning rate.
  • factivate (float): Fraction of inactive couplings to activate at each step.
  • gsteps (int): Number of gradient updates to be performed on a given graph.
  • fi_val (Optional[torch.Tensor], optional): Single-point frequencies of the validation data. Defaults to None.
  • fij_val (Optional[torch.Tensor], optional): Two-point frequencies of the validation data. Defaults to None.
  • l2_reg (float, optional): L2 regularization coefficient. Defaults to 0.0.

Returns: Updated chains, parameters, and training history.


function train_edDCA

train_edDCA(
    sampler: Callable[, Tensor],
    chains: Tensor,
    fi_target: Tensor,
    fij_target: Tensor,
    params: dict[str, Tensor],
    mask: Tensor,
    lr: float,
    nsweeps: int,
    target_pearson: float,
    target_density: float,
    drate: float,
    fi_val: Tensor | None = None,
    fij_val: Tensor | None = None,
    l2_reg: float = 0.0,
    max_epochs: int = 10000,
    controller: TrainingController | None = None,
    max_gradient_steps: int | None = None,
    inner_gradient_steps: int = 10000
) → tuple[Tensor, dict[str, Tensor], dict[str, list[Any]]]

Fits an edDCA model on the training data and saves the results in a file.

Args:

  • sampler (Callable): Sampling function to be used.
  • chains (torch.Tensor): Initialization of the Markov chains.
  • fi_target (torch.Tensor): Single-point frequencies of the data.
  • fij_target (torch.Tensor): Two-point frequencies of the data.
  • params (Dict[str, torch.Tensor]): Initialization of the model's parameters.
  • mask (torch.Tensor): Initialization of the coupling matrix's mask.
  • lr (float): Learning rate.
  • nsweeps (int): Number of Monte Carlo steps to update the state of the model.
  • target_pearson (float): Pearson correlation coefficient on the two-points statistics to be reached.
  • target_density (float): Target density of the coupling matrix.
  • drate (float): Percentage of active couplings to be pruned at each decimation step.
  • fi_val (Optional[torch.Tensor], optional): Single-point frequencies of the validation data. Defaults to None.
  • fij_val (Optional[torch.Tensor], optional): Two-point frequencies of the validation data. Defaults to None.
  • l2_reg (float, optional): L2 regularization coefficient. Defaults to 0.0.

Returns: Updated chains, parameters, and training history.


function train_edgeDCA

train_edgeDCA(
    sampler: Callable[, Tensor],
    fi_target: Tensor,
    fij_target: Tensor,
    fi_pseudocounted: Tensor,
    fij_pseudocounted: Tensor,
    params: dict[str, Tensor],
    mask: Tensor,
    chains: Tensor,
    target_pearson: float,
    nsweeps: int,
    max_epochs: int,
    pseudo_count: float,
    fi_val: Tensor | None = None,
    fij_val: Tensor | None = None,
    controller: TrainingController | None = None,
    empirical_pseudocount: float = 1e-06
) → tuple[Tensor, dict[str, Tensor], dict[str, list[Any]]]

Fits an edge activation DCA model (edgeDCA) on the training data and saves the results in a file.

Args:

  • sampler (Callable): Sampling function to be used.
  • fi_target (torch.Tensor): Single-point frequencies of the data.
  • fij_target (torch.Tensor): Two-point frequencies of the data.
  • fi_pseudocounted (torch.Tensor): Pseudocounted single-point frequencies.
  • fij_pseudocounted (torch.Tensor): Pseudocounted two-point frequencies.
  • params (Dict[str, torch.Tensor]): Initialization of the model's parameters.
  • mask (torch.Tensor): Initialization of the coupling matrix's mask.
  • chains (torch.Tensor): Initialization of the Markov chains.
  • target_pearson (float): Pearson correlation coefficient on the two-points statistics to be reached.
  • nsweeps (int): Number of Monte Carlo steps to update the state of the model.
  • max_epochs (int): Maximum number of epochs to be performed.
  • pseudo_count (float): Pseudo count for the single and two points statistics. Acts as a regularization.
  • fi_val (Optional[torch.Tensor], optional): Single-point frequencies of the validation data. Defaults to None.
  • fij_val (Optional[torch.Tensor], optional): Two-point frequencies of the validation data. Defaults to None.

Returns: Updated chains, parameters, and training history.


This file was automatically generated via lazydocs.