GOOD.ood_algorithms.algorithms.EERM

Implementation of the EERM algorithm from “Handling Distribution Shifts on Graphs: An Invariance Perspective” paper

Classes

EERM(config)

Implementation of the EERM algorithm from "Handling Distribution Shifts on Graphs: An Invariance Perspective" paper

class GOOD.ood_algorithms.algorithms.EERM.EERM(config: Union[CommonArgs, Munch])[source]

Bases: BaseOODAlg

Implementation of the EERM algorithm from “Handling Distribution Shifts on Graphs: An Invariance Perspective” paper

Args:

config (Union[CommonArgs, Munch]): munchified dictionary of args (config.device, config.dataset.num_envs, config.ood.ood_param)

loss_calculate(raw_pred: Tensor, targets: Tensor, mask: Tensor, node_norm: Tensor, config: Union[CommonArgs, Munch]) Tensor[source]

Calculate loss

Parameters
  • raw_pred (Tensor) – model predictions

  • targets (Tensor) – input labels

  • mask (Tensor) – NAN masks for data formats

  • node_norm (Tensor) – node weights for normalization (for node prediction only)

  • config (Union[CommonArgs, Munch]) – munchified dictionary of args (config.metric.loss_func(), config.model.model_level)

config = munchify({model: {model_level: str('graph')},
                       metric: {loss_func: Accuracy}
                       })
Returns (Tensor):

cross entropy loss

loss_postprocess(loss: Tensor, data: Batch, mask: Tensor, config: Union[CommonArgs, Munch], **kwargs) Tensor[source]

Process loss based on EERM algorithm

Parameters
  • loss (Tensor) – base loss between model predictions and input labels

  • data (Batch) – input data

  • mask (Tensor) – NAN masks for data formats

  • config (Union[CommonArgs, Munch]) – munchified dictionary of args (config.device, config.dataset.num_envs, config.ood.ood_param)

config = munchify({device: torch.device('cuda'),
                       dataset: {num_envs: int(10)},
                       ood: {ood_param: float(0.1)}
                       })
Returns (Tensor):

loss based on EERM algorithm

stage_control(config: Union[CommonArgs, Munch])[source]

Set valuables before each epoch. Largely used for controlling multi-stage training and epoch related parameter settings.

Parameters

config – munchified dictionary of args.