pyprobound.aggregate.Contribution

class Contribution(binding, train_activity=True, log_activity=-inf, activity_heuristic=0.05)

Bases: Transform

Models the activity \(\alpha\) of a Binding component.

\[\alpha_a = \frac{[\text{P}_a]}{K_{\text{D}, a} (S_0)}\]
binding

The binding component whose contribution is modeled.

Type:

Binding

log_activity

The activity \(\alpha\) in log space.

Type:

Tensor

__init__(binding, train_activity=True, log_activity=-inf, activity_heuristic=0.05)

Initializes the contribution model.

Parameters:
  • binding (Binding) – The Binding component whose contribution will be modeled.

  • train_activity (bool) – Whether to train the activity \(\alpha\).

  • log_activity (float) – The initial value of log_activity.

  • activity_heuristic (float) – The fraction of the total aggregate that the contribution will be set to when it is first optimized.

Methods

cache(fun)

Decorator for a function to cache its output.

check_length_consistency()

Checks that input lengths of Binding components are consistent.

components()

Iterator of child components.

expected_log_contribution()

Calculates the expected log contribution.

forward(seqs)

Calculates the log contribution of a Binding to the Aggregate.

freeze()

Turns off gradient calculation for all parameters.

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.

set_contribution([log_contribution, ...])

Sets the activity so that E[log contribution] = log_contribution.

unfreeze([parameter])

Turns on gradient calculation for the specified parameter.

Attributes

unfreezable

alias of Literal['all', 'activity']

Non-Inherited Members

unfreezable

alias of Literal[‘all’, ‘activity’]

components()

Iterator of child components.

Return type:

Iterator[Binding]

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

expected_log_contribution()

Calculates the expected log contribution.

Return type:

float

forward(seqs)

Calculates the log contribution of a Binding to the Aggregate.

\[\log \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 contribution tensor of shape \((\text{minibatch},)\).

set_contribution(log_contribution=0, only_decrease=False)

Sets the activity so that E[log contribution] = log_contribution.

Parameters:
  • log_contribution (float) – The new value of the expected log contribution.

  • only_decrease (bool) – If True, update the activity only if the contribution would decrease

Return type:

None