Multitask KISS-GP IndexError
See original GitHub issueIn Multitask_GP_Regression_Scalable_With_KISSGP.ipynb replacing test_x = torch.linspace(0, 1, 51)
with test_x = torch.zeros(1)
, i.e., predicting on a single test point gives the following error:
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-46-17c4b6da319c> in <module>()
11 with torch.no_grad():
12 test_x = torch.zeros(1)
---> 13 observed_pred = likelihood(model(test_x))
14 # Get mean
15 mean = observed_pred.mean()
~/anaconda/envs/py3/lib/python3.6/site-packages/gpytorch/models/exact_gp.py in __call__(self, *args, **kwargs)
142 n_train=n_train,
143 likelihood=self.likelihood,
--> 144 precomputed_cache=self.mean_cache,
145 )
146 predictive_covar, covar_cache = exact_predictive_covar(
~/anaconda/envs/py3/lib/python3.6/site-packages/gpytorch/functions/__init__.py in exact_predictive_mean(full_covar, full_mean, train_labels, n_train, likelihood, precomputed_cache)
89
90 full_covar = NonLazyVariable(full_covar)
---> 91 return full_covar.exact_predictive_mean(full_mean, train_labels, n_train, likelihood, precomputed_cache)
92
93
~/anaconda/envs/py3/lib/python3.6/site-packages/gpytorch/lazy/lazy_evaluated_kernel_variable.py in exact_predictive_mean(self, full_mean, train_labels, n_train, likelihood, precomputed_cache)
124 else:
125 return super(LazyEvaluatedKernelVariable, self).exact_predictive_mean(
--> 126 full_mean, train_labels, n_train, likelihood, precomputed_cache
127 )
128
~/anaconda/envs/py3/lib/python3.6/site-packages/gpytorch/lazy/lazy_variable.py in exact_predictive_mean(self, full_mean, train_labels, n_train, likelihood, precomputed_cache)
427 else:
428 test_train_covar = self[n_train:, :n_train]
--> 429 res = test_train_covar.matmul(precomputed_cache)
430 if res.ndimension() == 3:
431 res = res.squeeze(-1)
~/anaconda/envs/py3/lib/python3.6/site-packages/gpytorch/lazy/lazy_variable.py in matmul(self, tensor)
632 raise RuntimeError
633
--> 634 func = Matmul(self.representation_tree())
635 return func(tensor, *self.representation())
636
~/anaconda/envs/py3/lib/python3.6/site-packages/gpytorch/lazy/lazy_evaluated_kernel_variable.py in representation_tree(self)
112
113 def representation_tree(self):
--> 114 return LazyVariableRepresentationTree(self.evaluate_kernel())
115
116 def evaluate(self):
~/anaconda/envs/py3/lib/python3.6/site-packages/gpytorch/lazy/lazy_evaluated_kernel_variable.py in evaluate_kernel(self)
96 x2 = self.x2
97
---> 98 self._cached_kernel_eval = super(Kernel, self.kernel).__call__(x1, x2, **self.params)
99 if self.squeeze_row:
100 self._cached_kernel_eval.squeeze_(-2)
~/anaconda/envs/py3/lib/python3.6/site-packages/gpytorch/module.py in __call__(self, *inputs, **kwargs)
160
161 def __call__(self, *inputs, **kwargs):
--> 162 outputs = self.forward(*inputs, **kwargs)
163 if torch.is_tensor(outputs) or isinstance(outputs, RandomVariable) or isinstance(outputs, LazyVariable):
164 return outputs
~/anaconda/envs/py3/lib/python3.6/site-packages/gpytorch/kernels/multitask_kernel.py in forward(self, x1, x2)
62 task_indices = torch.arange(self.n_tasks, device=x1.device).long()
63 covar_i = self.task_covar_module(task_indices).evaluate_kernel()
---> 64 covar_x = self.data_covar_module.forward(x1, x2)
65 if covar_x.size(0) == 1:
66 covar_x = covar_x[0]
~/anaconda/envs/py3/lib/python3.6/site-packages/gpytorch/kernels/grid_interpolation_kernel.py in forward(self, x1, x2, **kwargs)
56 base_lazy_var = base_lazy_var.repeat(x1.size(0), 1, 1)
57
---> 58 left_interp_indices, left_interp_values = self._compute_grid(x1)
59 if torch.equal(x1.data, x2.data):
60 right_interp_indices = left_interp_indices
~/anaconda/envs/py3/lib/python3.6/site-packages/gpytorch/kernels/grid_interpolation_kernel.py in _compute_grid(self, inputs)
39 batch_size, n_data, n_dimensions = inputs.size()
40 inputs = inputs.view(batch_size * n_data, n_dimensions)
---> 41 interp_indices, interp_values = Interpolation().interpolate(Variable(self.grid), inputs)
42 interp_indices = interp_indices.view(batch_size, n_data, -1)
43 interp_values = interp_values.view(batch_size, n_data, -1)
~/anaconda/envs/py3/lib/python3.6/site-packages/gpytorch/utils/interpolation.py in interpolate(self, x_grid, x_target, interp_points)
114 dim_interp_values[left_boundary_pts[j], :] = 0
115 dim_interp_values[left_boundary_pts[j], closest_from_first[j]] = 1
--> 116 lower_grid_pt_idxs[left_boundary_pts[j]] = 0
117
118 right_boundary_pts = torch.nonzero(lower_grid_pt_idxs > num_grid_points - num_coefficients)
IndexError: too many indices for tensor of dimension 0
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Multitask KISS-GP single test point error · Issue #250 · cornellius-gp ...
Multitask KISS-GP single test point error #250 ... num_grid_points - num_coefficients) IndexError: too many indices for tensor of dimension 0.
Read more >Source code for gpytorch.distributions.multivariate_normal
[docs]class MultivariateNormal(TMultivariateNormal, Distribution): """ Constructs a multivariate normal random variable, based on mean and covariance.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Okay - the code in 1b809b3 should fix the problem you were seeing with 2D inputs. As far as test predictions for a single point - this commit might also fix that. If not, would you mind opening a separate issue for that?
Seems working, thank you!