Cell for using initialize
"\n",
"model = FancyGPWithPriors(train_x, train_y, likelihood)"
]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Initializing hyperparameters in One Call\n",
+ "\n",
+ "For convenience, GPyTorch modules also define an `initialize` method that allow you to update a full dictionary of parameters on submodules. For example:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 33,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "1.0000001192092896 0.4999999701976776 2.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "hypers = {\n",
+ " 'likelihood.noise_covar.noise': torch.tensor(1.),\n",
+ " 'covar_module.base_kernel.lengthscale': torch.tensor(0.5),\n",
+ " 'covar_module.outputscale': torch.tensor(2.),\n",
+ "}\n",
+ "\n",
+ "model.initialize(**hypers)\n",
+ "print(\n",
+ " model.likelihood.noise_covar.noise.item(),\n",
+ " model.covar_module.base_kernel.lengthscale.item(),\n",
+ " model.covar_module.outputscale.item()\n",
+ ")"
+ ]
}
],
"metadata": {
