+def create_sequences_pairs(train = False):
+ nb, length = 10000, 1024
+ noise_level = 2e-2
+
+ ha = torch.randint(args.nb_classes, (nb, ), device = device) + 1
+ if args.independent:
+ hb = torch.randint(args.nb_classes, (nb, ), device = device)
+ else:
+ hb = ha
+
+ pos = torch.empty(nb, device = device).uniform_(0.0, 0.9)
+ a = torch.linspace(0, 1, length, device = device).view(1, -1).expand(nb, -1)
+ a = a - pos.view(nb, 1)
+ a = (a >= 0).float() * torch.exp(-a * math.log(2) / 0.1)
+ a = a * ha.float().view(-1, 1).expand_as(a) / (1 + args.nb_classes)
+ noise = a.new(a.size()).normal_(0, noise_level)
+ a = a + noise
+
+ pos = torch.empty(nb, device = device).uniform_(0.0, 0.5)
+ b1 = torch.linspace(0, 1, length, device = device).view(1, -1).expand(nb, -1)
+ b1 = b1 - pos.view(nb, 1)
+ b1 = (b1 >= 0).float() * torch.exp(-b1 * math.log(2) / 0.1) * 0.25
+ pos = pos + hb.float() / (args.nb_classes + 1) * 0.5
+ b2 = torch.linspace(0, 1, length, device = device).view(1, -1).expand(nb, -1)
+ b2 = b2 - pos.view(nb, 1)
+ b2 = (b2 >= 0).float() * torch.exp(-b2 * math.log(2) / 0.1) * 0.25
+
+ b = b1 + b2
+ noise = b.new(b.size()).normal_(0, noise_level)
+ b = b + noise
+
+ # a = (a - a.mean()) / a.std()
+ # b = (b - b.mean()) / b.std()
+
+ return a, b, ha
+
+######################################################################
+
+class NetForImagePair(nn.Module):