MCPcopy Index your code
hub / github.com/PyGCL/PyGCL / mixup

Function mixup

GCL/augmentors/functional.py:46–61  ·  view source on GitHub ↗

Randomly mixup node embeddings or features with other nodes'. Args: x: The latent embedding or node feature. alpha: The hyperparameter controlling the mixup coefficient. Returns: torch.Tensor: Embeddings or features resulting from mixup.

(x: torch.Tensor, alpha: float)

Source from the content-addressed store, hash-verified

44
45
46def mixup(x: torch.Tensor, alpha: float) -> torch.Tensor:
47 """
48 Randomly mixup node embeddings or features with other nodes'.
49
50 Args:
51 x: The latent embedding or node feature.
52 alpha: The hyperparameter controlling the mixup coefficient.
53
54 Returns:
55 torch.Tensor: Embeddings or features resulting from mixup.
56 """
57 device = x.device
58 mixup_idx = get_mixup_idx(x).to(device)
59 lambda_ = Uniform(alpha, 1.).sample([1]).to(device)
60 x = (1 - lambda_) * x + lambda_ * x[mixup_idx]
61 return x
62
63
64def multiinstance_mixup(x1: torch.Tensor, x2: torch.Tensor,

Callers

nothing calls this directly

Calls 2

get_mixup_idxFunction · 0.85
sampleMethod · 0.45

Tested by

no test coverage detected