gflownet.losses.detailedbalance

Detailed Balance loss or objective for training GFlowNets.

The Detailed Balance (DB) loss or objective was defined by Malkin et al. (2022):

Classes

DetailedBalance

Initialization method for the Detailed Balance loss class.

Module Contents

class gflownet.losses.detailedbalance.DetailedBalance(**kwargs)[source]

Bases: gflownet.losses.base.BaseLoss

Initialization method for the Detailed Balance loss class.

name[source]

The name of the loss or objective function: Detailed Balance

Type:

str

acronym[source]

The acronym of the loss or objective function: DB

Type:

str

id[source]

The identifier of the loss or objective function: detailedbalance

Type:

str

name = 'Detailed Balance'[source]
acronym = 'DB'[source]
id = 'detailedbalance'[source]
requires_backward_policy()[source]

Returns True if the loss function requires a backward policy.

The Detailed Balance loss does require a backward policy model, hence True is returned.

Returns:

True

Return type:

bool

requires_state_flow_model()[source]

Returns True if the loss function requires a state flow model.

The Detailed Balance loss does require a state flow model, hence True is returned.

Returns:

True

Return type:

bool

is_defined_for_continuous()[source]

Returns True if the loss function is well defined for continuous GFlowNets, that is continuous environments, or False otherwise.

The Detailed Balance loss is well defined for continuous GFlowNets, therefore this method returns True.

Returns:

True

Return type:

bool

compute_losses_of_batch(batch)[source]

Computes the Detailed Balance loss for each state of the input batch.

The Detailed Balance (DB) loss or objective is computed in this method as is defined in Equation 11 of Malkin et al. (2022).

Parameters:

batch (Batch) – A batch of states.

Returns:

losses (tensor) – The loss of each state in the batch.

Return type:

torchtyping.TensorType[batch_size]

aggregate_losses_of_batch(losses, batch)[source]

Aggregates the losses computed from a batch to obtain the overall average loss and the average loss over terminating states and intermediate states.

The result is returned as a dictionary with the following items: - ‘all’: Overall average loss - ‘Loss (terminating)’: Average loss over terminating states - ‘Loss (non-term.)’: Average loss over non-terminating (intermediate) states

Parameters:
  • losses (tensor) – The loss of each state in the batch.

  • batch (Batch) – A batch of states.

Returns:

loss_dict (dict) – A dictionary of loss aggregations.

Return type:

dict[str, float]