Update notebook to use grid creation helper.
},
{
"cell_type": "code",
- "execution_count": 9,
+ "execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
" grid_diff = float(grid_bounds[i][1] - grid_bounds[i][0]) / (grid_size - 2)\n",
" grid[:, i] = torch.linspace(grid_bounds[i][0] - grid_diff, grid_bounds[i][1] + grid_diff, grid_size)\n",
"\n",
- "# Here we actually construct the full grid. We only do this in the example notebook\n",
- "# to easily get the training labels. We won't need the full grid constructed ever.\n",
- "grid_size = grid.size(-2)\n",
- "grid_dim = grid.size(-1)\n",
- "grid_data = torch.zeros(int(pow(grid_size, grid_dim)), grid_dim)\n",
- "prev_points = None\n",
- "for i in range(grid_dim):\n",
- " for j in range(grid_size):\n",
- " grid_data[j * grid_size ** i : (j + 1) * grid_size ** i, i].fill_(grid[j, i])\n",
- " if prev_points is not None:\n",
- " grid_data[j * grid_size ** i : (j + 1) * grid_size ** i, :i].copy_(prev_points)\n",
- " prev_points = grid_data[: grid_size ** (i + 1), : (i + 1)]\n",
- " \n",
- "train_y = torch.sin((grid_data[:, 0] + grid_data[:, 1]) * (2 * math.pi)) + torch.randn_like(grid_data[:, 0]).mul(0.01)\n",
- "train_x = grid_data"
+ "train_x = gpytorch.utils.grid.create_data_from_grid(grid)\n",
+ "train_y = torch.sin((train_x[:, 0] + train_x[:, 1]) * (2 * math.pi)) + torch.randn_like(train_x[:, 0]).mul(0.01)"
]
},
{
