2025 USA-NA-AIO Round 2, Problem 1, Part 7

Part 7 (10 points, coding task)

In this part, you are asked to create the dataset \mathcal D_{BC}.

  1. Define dataset \mathcal D_{BC} in the way that for each \left( t, x \right) \in \mathcal D_{BC}, x is either 0 or 1, and t is evenly sampled from \left\{ 0, 0.01, 0.02, \cdots , 0.98, 0.99, 1 \right\}. Therefore, | \mathcal D_{BC} | = 2 \cdot 101 = 202.

  2. The dataset shall be a tensor with name dataset_train_BC and shape (202,2).

  3. Set dataset_train_BC.requires_grad = True.

  4. Print dataset_train_BC.requires_grad and dataset_train_IC.shape.

### WRITE YOUR SOLUTION HERE ###

num_samples = 202

data_0 = torch.stack([torch.linspace(0, 1, num_samples//2), torch.zeros(num_samples//2)], dim=1)
data_1 = torch.stack([torch.linspace(0, 1, num_samples//2), torch.ones(num_samples//2)], dim=1)
dataset_train_BC = torch.cat([data_0, data_1], dim=0)
dataset_train_BC.requires_grad_(True)

print(dataset_train_BC.requires_grad)
print(dataset_train_BC.shape)

""" END OF THIS PART """