cornellius-gp / gpytorch

A highly efficient implementation of Gaussian Processes in PyTorch
MIT License
3.56k stars 559 forks source link

pytorch 0.2 problem #10

Closed chalesguo closed 6 years ago

chalesguo commented 7 years ago

from gpytorch.inference import Inference infer = Inference(prior_observation_model) posterior_observation_model = infer.run(train_x, train_y, max_inference_steps=20)


RuntimeError Traceback (most recent call last)

in () 1 from gpytorch.inference import Inference 2 infer = Inference(prior_observation_model) ----> 3 posterior_observation_model = infer.run(train_x, train_y, max_inference_steps=20) /usr/local/lib/python3.5/dist-packages/gpytorch/inference/inference.py in run(self, train_x, train_y, optimize, **kwargs) 77 orig_observation_model = self.observation_model 78 self.observation_model = deepcopy(self.observation_model) ---> 79 new_observation_model = self.run_(train_x, train_y, optimize=optimize, **kwargs) 80 self.observation_model = orig_observation_model 81 return new_observation_model /usr/local/lib/python3.5/dist-packages/gpytorch/inference/inference.py in run_(self, train_x, train_y, inducing_points, optimize, max_inference_steps, **kwargs) 63 for i in range(max_inference_steps): 64 for param_group in param_groups: ---> 65 param_group.update(log_likelihood_closure) 66 67 has_converged = all([param_group.has_converged(log_likelihood_closure) for param_group in param_groups]) /usr/local/lib/python3.5/dist-packages/gpytorch/parameters/mle_parameter_group.py in update(self, log_likelihood_closure) 36 return loss 37 ---> 38 loss = optimizer.step(step_closure) 39 if isinstance(loss, Variable): 40 self.previous_loss = loss.data.squeeze()[0] /usr/local/lib/python3.5/dist-packages/gpytorch/utils/lbfgs.py in step(self, closure) 99 100 # evaluate initial f(x) and df/dx --> 101 orig_loss = closure() 102 loss = orig_loss.data[0] 103 current_evals = 1 /usr/local/lib/python3.5/dist-packages/gpytorch/utils/__init__.py in wrapped_function(*args, **kwargs) 31 32 else: ---> 33 raise e 34 35 return result /usr/local/lib/python3.5/dist-packages/gpytorch/utils/__init__.py in wrapped_function(*args, **kwargs) 19 def wrapped_function(*args, **kwargs): 20 try: ---> 21 result = function(*args, **kwargs) 22 self.n_trials = 0 23 /usr/local/lib/python3.5/dist-packages/gpytorch/parameters/mle_parameter_group.py in step_closure() 32 optimizer.zero_grad() 33 optimizer.n_iter += 1 ---> 34 loss = -log_likelihood_closure() 35 loss.backward() 36 return loss /usr/local/lib/python3.5/dist-packages/gpytorch/inference/inference.py in log_likelihood_closure() 54 self.observation_model.zero_grad() 55 output = self.observation_model.forward(*inducing_points) ---> 56 return self.observation_model.marginal_log_likelihood(output, train_y) 57 58 if optimize: /usr/local/lib/python3.5/dist-packages/gpytorch/inference/posterior_models.py in marginal_log_likelihood(self, output, train_y, num_samples) 131 132 kl_divergence = gpytorch.mvn_kl_divergence(self.variational_parameters.variational_mean, --> 133 chol_var_covar, inducing_mean, inducing_covar) 134 135 return log_likelihood.squeeze() - kl_divergence /usr/local/lib/python3.5/dist-packages/gpytorch/__init__.py in mvn_kl_divergence(mean_1, chol_covar_1, mean_2, covar_2) 35 36 def mvn_kl_divergence(mean_1, chol_covar_1, mean_2, covar_2): ---> 37 return MVNKLDivergence()(mean_1, chol_covar_1, mean_2, covar_2) /usr/local/lib/python3.5/dist-packages/gpytorch/math/functions/mvn_kl_divergence.py in __call__(self, mu1_var, chol_covar1_var, mu2_var, covar2_var) 32 # Multiplying that by -2 gives us two of the terms in the KL divergence 33 # (plus an unwanted constant that we can subtract out). ---> 34 K_part = ExactGPMarginalLogLikelihood()(covar2_var, mu_diffs) 35 36 # Get logdet(\Sigma_{1}) /usr/local/lib/python3.5/dist-packages/gpytorch/math/functions/invmv.py in __call__(self, matrix_var, vector_var) 7 """ 8 def __call__(self, matrix_var, vector_var): ----> 9 res = super(Invmv, self).__call__(matrix_var, vector_var.view(-1, 1)) 10 return res.view(-1) /usr/local/lib/python3.5/dist-packages/gpytorch/math/functions/invmm.py in __call__(self, input_1_var, input_2_var) 48 orig_data = input_1_var.data 49 input_1_var.data = input_1_var.chol_data ---> 50 res = super(Invmm, self).__call__(input_1_var, input_2_var) 51 52 # Revert back to original data /usr/local/lib/python3.5/dist-packages/gpytorch/math/functions/exact_gp_marginal_log_likelihood.py in forward(self, chol_mat, y) 7 def forward(self, chol_mat, y): 8 mat_inv_y = y.potrs(chol_mat) ----> 9 res = mat_inv_y.dot(y) # Inverse quad 10 res += chol_mat.diag().log_().sum() * 2 # Log determinant 11 res += math.log(2 * math.pi) * len(y) RuntimeError: Expected argument self to have 1 dimension(s), but has 2 at /pytorch/torch/csrc/generic/TensorMethods.cpp:23020
gpleiss commented 7 years ago

Have you pulled recently? This problem should be fixed by now. Also, be warned that there interface is changing significantly...

gpleiss commented 6 years ago

I think this issue should be resolved now, so marking it as closed.