Skip to content

Abstract Weights

popinn.AbstractWeights ¤

Abstract base class for per-term loss weighting schemes.

Subclasses store the weighting parameters in values and implement the combine method, which folds the per-term scalar residuals into the total weighted loss.

Fields:

  • values (dict): the weights, keyed by the set of corresponding ResidualTerm.name strings. Whether the weights are static constants or trainable leaves is decided by the concrete subclass.
Source code in src/popinn/loss.py
class AbstractWeights(eqx.Module):
    """
    Abstract base class for per-term loss weighting schemes.

    Subclasses store the weighting parameters in `values` and implement the
    `combine` method, which folds the per-term scalar residuals into the total weighted loss.

    **Fields**:

    - `values` (`dict`): the weights, keyed by the set of corresponding `ResidualTerm.name` strings. Whether the
        weights are static constants or trainable leaves is decided by the concrete subclass.
    """

    values: eqx.AbstractVar[dict]

    @abc.abstractmethod
    def combine(self, residuals: dict) -> Float[Array, ""]:
        """
        Combine per-term scalar residuals into the weighted total.

        Args:
            residuals (dict): A mapping from each `ResidualTerm.name` to that term's scalar
                value.

        Returns:
            (Float[Array, '']): The total weighted loss.
        """
        raise NotImplementedError
combine(residuals) ¤

Combine per-term scalar residuals into the weighted total.

Parameters:

Name Type Description Default
residuals dict

A mapping from each ResidualTerm.name to that term's scalar value.

required

Returns:

Type Description
jaxtyping.Float[jax.Array, '']

The total weighted loss.

Source code in src/popinn/loss.py
@abc.abstractmethod
def combine(self, residuals: dict) -> Float[Array, ""]:
    """
    Combine per-term scalar residuals into the weighted total.

    Args:
        residuals (dict): A mapping from each `ResidualTerm.name` to that term's scalar
            value.

    Returns:
        (Float[Array, '']): The total weighted loss.
    """
    raise NotImplementedError