Repository: cornellius-gp/gpytorch

Issue:
Linear kernel's variance prior is broken
Repro: 
[linear_kernel_prior_issue.ipynb.txt](https://github.com/cornellius-gp/gpytorch/files/2979717/linear_kernel_prior_issue.ipynb.txt)



Discussion:

Resolving patch:
diff --git a/gpytorch/kernels/linear_kernel.py b/gpytorch/kernels/linear_kernel.py
--- a/gpytorch/kernels/linear_kernel.py
+++ b/gpytorch/kernels/linear_kernel.py
@@ -1,6 +1,7 @@
 #!/usr/bin/env python3
 
 import torch
+import warnings
 from .kernel import Kernel
 from ..lazy import MatmulLazyTensor, RootLazyTensor
 
@@ -12,13 +13,12 @@ class LinearKernel(Kernel):
 
     .. math::
         \begin{equation*}
-            k_\text{Linear}(\mathbf{x_1}, \mathbf{x_2}) = (\mathbf{x_1} - \mathbf{o})^\top
-            (\mathbf{x_2} - \mathbf{o}) + v.
+            k_\text{Linear}(\mathbf{x_1}, \mathbf{x_2}) = v\mathbf{x_1}^\top
+            \mathbf{x_2}.
         \end{equation*}
 
     where
 
-    * :math:`\mathbf o` is an :attr:`offset` parameter.
     * :math:`v` is a :attr:`variance` parameter.
 
 
@@ -32,24 +32,37 @@ class LinearKernel(Kernel):
         :math:`O(nd)` time and space.
 
     Args:
-        :attr:`num_dimensions` (int):
-            Number of data dimensions to expect. This
-            is necessary to create the offset parameter.
         :attr:`variance_prior` (:class:`gpytorch.priors.Prior`):
             Prior over the variance parameter (default `None`).
-        :attr:`offset_prior` (:class:`gpytorch.priors.Prior`):
-            Prior over the offset parameter (default `None`).
         :attr:`active_dims` (list):
             List of data dimensions to operate on.
             `len(active_dims)` should equal `num_dimensions`.
     """
 
-    def __init__(self, num_dimensions, variance_prior=None, active_dims=None):
+    def __init__(self, num_dimensions=None, offset_prior=None, variance_prior=None, active_dims=None):
         super(LinearKernel, self).__init__(active_dims=active_dims)
+        if num_dimensions is not None:
+            warnings.warn(
+                "The `num_dimensions` argument is deprecated and no longer used.",
+                DeprecationWarning
+            )
+            self.register_parameter(
+                name="offset",
+                parameter=torch.nn.Parameter(torch.zeros(1, 1, num_dimensions))
+            )
+        if offset_prior is not None:
+            warnings.warn(
+                "The `offset_prior` argument is deprecated and no longer used.",
+                DeprecationWarning
+            )
         self.register_parameter(name="raw_variance", parameter=torch.nn.Parameter(torch.zeros(1)))
-        self.register_parameter(name="offset", parameter=torch.nn.Parameter(torch.zeros(1, 1, num_dimensions)))
         if variance_prior is not None:
-            self.register_prior("variance_prior", variance_prior, "variance")
+            self.register_prior(
+                "variance_prior",
+                variance_prior,
+                lambda: self.variance,
+                lambda v: self._set_variance(v)
+            )
 
     @property
     def variance(self):


Test patch:
diff --git a/test/kernels/test_linear_kernel.py b/test/kernels/test_linear_kernel.py
--- a/test/kernels/test_linear_kernel.py
+++ b/test/kernels/test_linear_kernel.py
@@ -10,7 +10,7 @@ def test_computes_linear_function_rectangular(self):
         a = torch.tensor([4, 2, 8], dtype=torch.float).view(3, 1)
         b = torch.tensor([0, 2, 1], dtype=torch.float).view(3, 1)
 
-        kernel = LinearKernel(num_dimensions=1).initialize(variance=1.0)
+        kernel = LinearKernel().initialize(variance=1.0)
         kernel.eval()
         actual = torch.matmul(a, b.t())
         res = kernel(a, b).evaluate()
@@ -24,7 +24,7 @@ def test_computes_linear_function_rectangular(self):
     def test_computes_linear_function_square(self):
         a = torch.tensor([[4, 1], [2, 0], [8, 3]], dtype=torch.float)
 
-        kernel = LinearKernel(1).initialize(variance=3.14)
+        kernel = LinearKernel().initialize(variance=3.14)
         kernel.eval()
         actual = torch.matmul(a, a.t()) * 3.14
         res = kernel(a, a).evaluate()
@@ -50,7 +50,7 @@ def test_computes_linear_function_square(self):
     def test_computes_linear_function_square_batch(self):
         a = torch.tensor([[[4, 1], [2, 0], [8, 3]], [[1, 1], [2, 1], [1, 3]]], dtype=torch.float)
 
-        kernel = LinearKernel(1).initialize(variance=1.0)
+        kernel = LinearKernel().initialize(variance=1.0)
         kernel.eval()
         actual = torch.matmul(a, a.transpose(-1, -2))
         res = kernel(a, a).evaluate()