Randomly mixup node embeddings or features with nodes from other views. Args: x1: The latent embedding or node feature from one view. x2: The latent embedding or node feature from the other view. alpha: The mixup coefficient `\lambda` follows `Beta(\alpha, \alpha)`.
(x1: torch.Tensor, x2: torch.Tensor,
alpha: float, shuffle=False)
| 62 | |
| 63 | |
| 64 | def multiinstance_mixup(x1: torch.Tensor, x2: torch.Tensor, |
| 65 | alpha: float, shuffle=False) -> (torch.Tensor, torch.Tensor): |
| 66 | """ |
| 67 | Randomly mixup node embeddings or features with nodes from other views. |
| 68 | |
| 69 | Args: |
| 70 | x1: The latent embedding or node feature from one view. |
| 71 | x2: The latent embedding or node feature from the other view. |
| 72 | alpha: The mixup coefficient `\lambda` follows `Beta(\alpha, \alpha)`. |
| 73 | shuffle: Whether to use fixed negative samples. |
| 74 | |
| 75 | Returns: |
| 76 | (torch.Tensor, torch.Tensor): Spurious positive samples and the mixup coefficient. |
| 77 | """ |
| 78 | device = x1.device |
| 79 | lambda_ = Beta(alpha, alpha).sample([1]).to(device) |
| 80 | if shuffle: |
| 81 | mixup_idx = get_mixup_idx(x1).to(device) |
| 82 | else: |
| 83 | mixup_idx = x1.size(0) - torch.arange(x1.size(0)) - 1 |
| 84 | x_spurious = (1 - lambda_) * x1 + lambda_ * x2[mixup_idx] |
| 85 | |
| 86 | return x_spurious, lambda_ |
| 87 | |
| 88 | |
| 89 | def drop_feature(x: torch.Tensor, drop_prob: float) -> torch.Tensor: |
nothing calls this directly
no test coverage detected