Skip to content

conditional

A module for conditional unsupervised domain adaption losses.

ConditionalAdaptionLoss

Bases: Metric

The Conditional Adaptions loss is a combination of multiple losses, each of which is only applied to a subset of the incoming data.

The subsets are defined by fuzzy sets with a rectangular membership function. The prediction for each sample is checked against the fuzzy sets, and the corresponding loss is applied to the sample. The combined loss can be set as the sum of all components or their mean.

__init__(adaption_losses, fuzzy_sets, mean_over_sets=True)

Create a new Conditional Adaption loss over fuzzy sets.

The fuzzy sets' boundaries are inclusive on the left and exclusive on the right. The left boundary is supposed to be smaller than the right boundary.

This loss should not be used as a way to accumulate its value over multiple batches.

Parameters:

Name Type Description Default
adaption_losses Sequence[Metric]

The list of losses to be applied to the subsets.

required
fuzzy_sets List[Tuple[float, float]]

The fuzzy sets to be used for subset membership.

required
mean_over_sets bool

Whether to take the mean or the sum of the losses.

True

compute()

Compute the loss as either the sum or mean of all subset losses.

Returns:

Type Description
Tensor

The combined loss.

update(source, source_preds, target, target_preds)

Update the loss with the given data.

The predictions for the source and target data are checked against the fuzzy sets to determine membership.

Parameters:

Name Type Description Default
source Tensor

The source features.

required
source_preds Tensor

The predictions for the source features.

required
target Tensor

The target features.

required
target_preds Tensor

The predictions for the target features.

required