pyprobound.aggregate.Aggregate
- class Aggregate(contributions, train_concentration=False, target_concentration=1)
Bases:
TransformModels the weighted sum over an aggregate of different binding modes.
\[Z_{i} = \sum_a \frac{\alpha_a}{K^{rel}_{\text{D}, a} (S_i)}\]- contributions
The Contributions making up the aggregate.
- Type:
- log_target_concentration
The total protein concentration \([\text{P}]_T\) in log space.
- Type:
Tensor
- __init__(contributions, train_concentration=False, target_concentration=1)
Initializes the aggregate.
- Parameters:
contributions (
Iterable[Contribution]) – The contributions making up the aggregate.train_concentration (
bool) – Whether to train the protein concentration.target_concentration (
float) – Protein concentration, used for estimating the free protein concentration.
Methods
activity_heuristic(contribution[, frac])Sets the activity so that E[contribution] = frac * E[aggregate].
cache(fun)Decorator for a function to cache its output.
check_length_consistency()Checks that input lengths of Binding components are consistent.
Iterator of child components.
Calculates the expected log aggregate.
forward(seqs)Calculates the log aggregate \(\log Z_i\).
freeze()Turns off gradient calculation for all parameters.
from_binding(binding[, train_concentration, ...])Creates a new instance from the binding modes.
max_embedding_size()The maximum number of bytes needed to encode a sequence.
optim_procedure([ancestry, current_order])The sequential optimization procedure for all Binding components.
reload(checkpoint)Loads the model from a checkpoint file.
reload_from_state_dict(state_dict)Loads the model from a state dict.
save(checkpoint[, flank_lengths])Saves the model to a file with "state_dict" and "metadata" fields.
unfreeze([parameter])Turns on gradient calculation for the specified parameter.
Attributes
alias of
Literal['all', 'concentration']Non-Inherited Members
- unfreezable
alias of
Literal[‘all’, ‘concentration’]
- classmethod from_binding(binding, train_concentration=False, target_concentration=1, activity_heuristic=0.05)
Creates a new instance from the binding modes.
- Parameters:
binding (
Iterable[Binding]) – The binding modes driving enrichment.train_concentration (
bool) – Whether to train the protein concentration.target_concentration (
float) – Protein concentration, used for estimating the free protein concentration.activity_heuristic (
float) – The fraction of the total aggregate that the contribution will be set to when it is first optimized.
- Return type:
Self
- components()
Iterator of child components.
- Return type:
Iterator[Contribution]
- unfreeze(parameter='all')
Turns on gradient calculation for the specified parameter.
- Parameters:
parameter (unfreezable) – Parameter to be unfrozen, defaults to all parameters.
- Return type:
None
- optim_procedure(ancestry=None, current_order=None)
The sequential optimization procedure for all Binding components.
The optimization procedure is generated recursively through iteration over the child components of each module. All Binding components with the same specification returned from key() are trained jointly.
- Parameters:
ancestry (
tuple[Component,...] |None) – The parent components from the root for which the procedure is being generated to the current component.current_order (
dict[tuple[Spec,...],BindingOptim] |None) – Mapping of Binding component specifications to the sequential optimization procedure for those Binding components.
- Return type:
dict[tuple[Spec,...],BindingOptim]- Returns:
The current_order updated with the optimization of the current component’s children.
- expected_log_aggregate()
Calculates the expected log aggregate.
- Return type:
float
- forward(seqs)
Calculates the log aggregate \(\log Z_i\).
\[\log Z_{i} = \log\sum_a\frac{\alpha_a}{K^{rel}_{\text{D}, a} (S_i)}\]- Parameters:
seqs (
Tensor) – A sequence tensor of shape \((\text{minibatch},\text{length})\) or \((\text{minibatch},\text{in_channels},\text{length})\).- Return type:
Tensor- Returns:
The log aggregate tensor of shape \((\text{minibatch},)\).
- activity_heuristic(contribution, frac=None)
Sets the activity so that E[contribution] = frac * E[aggregate].
- Parameters:
contribution (
Contribution) – The Contribution whose activity will be updated.frac (
float|None) – The proportion of the aggregate the Binding contributes. If None, uses the activity_heuristic attribute of Contribution.
- Return type:
None