diff --git a/GPy/core/parameterization/ties_and_remappings.py b/GPy/core/parameterization/ties_and_remappings.py index bafa8a98..527bc47c 100644 --- a/GPy/core/parameterization/ties_and_remappings.py +++ b/GPy/core/parameterization/ties_and_remappings.py @@ -185,7 +185,7 @@ class Tie(Parameterized): def _check_change(self): changed = False if self.tied_param is not None: - for i in xrange(self.tied_param.size): + for i in range(self.tied_param.size): b0 = self.label_buf==self.label_buf[self.buf_idx[i]] b = self._highest_parent_.param_array[b0]!=self.tied_param[i] if b.sum()==0: @@ -212,11 +212,11 @@ class Tie(Parameterized): if self.tied_param is not None: self.tied_param.gradient = 0. [np.put(self.tied_param.gradient, i, self._highest_parent_.gradient[self.label_buf==self.label_buf[self.buf_idx[i]]].sum()) - for i in xrange(self.tied_param.size)] + for i in range(self.tied_param.size)] def propagate_val(self): if self.tied_param is not None: - for i in xrange(self.tied_param.size): + for i in range(self.tied_param.size): self._highest_parent_.param_array[self.label_buf==self.label_buf[self.buf_idx[i]]] = self.tied_param[i] diff --git a/GPy/examples/dimensionality_reduction.py b/GPy/examples/dimensionality_reduction.py index fe1fa1e5..46107a71 100644 --- a/GPy/examples/dimensionality_reduction.py +++ b/GPy/examples/dimensionality_reduction.py @@ -653,7 +653,7 @@ def ssgplvm_simulation_linear(): def sample_X(Q, pi): x = np.empty(Q) dies = np.random.rand(Q) - for q in xrange(Q): + for q in range(Q): if dies[q] < pi: x[q] = np.random.randn() else: @@ -663,7 +663,7 @@ def ssgplvm_simulation_linear(): Y = np.empty((N, D)) X = np.empty((N, Q)) # Generate data from random sampled weight matrices - for n in xrange(N): + for n in range(N): X[n] = sample_X(Q, pi) w = np.random.randn(D, Q) Y[n] = np.dot(w, X[n]) diff --git a/GPy/inference/latent_function_inference/posterior.py b/GPy/inference/latent_function_inference/posterior.py index 73d65df6..ea608cce 100644 --- a/GPy/inference/latent_function_inference/posterior.py +++ b/GPy/inference/latent_function_inference/posterior.py @@ -107,7 +107,7 @@ class Posterior(object): if self._precision is None: cov = np.atleast_3d(self.covariance) self._precision = np.zeros(cov.shape) # if one covariance per dimension - for p in xrange(cov.shape[-1]): + for p in range(cov.shape[-1]): self._precision[:,:,p] = pdinv(cov[:,:,p])[0] return self._precision @@ -125,7 +125,7 @@ class Posterior(object): if self._woodbury_inv is not None: winv = np.atleast_3d(self._woodbury_inv) self._woodbury_chol = np.zeros(winv.shape) - for p in xrange(winv.shape[-1]): + for p in range(winv.shape[-1]): self._woodbury_chol[:,:,p] = pdinv(winv[:,:,p])[2] #Li = jitchol(self._woodbury_inv) #self._woodbury_chol, _ = dtrtri(Li) @@ -160,7 +160,7 @@ class Posterior(object): elif self._covariance is not None: B = np.atleast_3d(self._K) - np.atleast_3d(self._covariance) self._woodbury_inv = np.empty_like(B) - for i in xrange(B.shape[-1]): + for i in range(B.shape[-1]): tmp, _ = dpotrs(self.K_chol, B[:,:,i]) self._woodbury_inv[:,:,i], _ = dpotrs(self.K_chol, tmp.T) return self._woodbury_inv diff --git a/GPy/inference/latent_function_inference/var_dtc_parallel.py b/GPy/inference/latent_function_inference/var_dtc_parallel.py index cb117af1..6f98668f 100644 --- a/GPy/inference/latent_function_inference/var_dtc_parallel.py +++ b/GPy/inference/latent_function_inference/var_dtc_parallel.py @@ -92,7 +92,7 @@ class VarDTC_minibatch(LatentFunctionInference): psi0_full = 0. YRY_full = 0. - for n_start in xrange(0,num_data,batchsize): + for n_start in range(0,num_data,batchsize): n_end = min(batchsize+n_start, num_data) if batchsize==num_data: Y_slice = Y diff --git a/GPy/inference/mcmc/hmc.py b/GPy/inference/mcmc/hmc.py index ec6399b6..fcc72591 100644 --- a/GPy/inference/mcmc/hmc.py +++ b/GPy/inference/mcmc/hmc.py @@ -39,7 +39,7 @@ class HMC: :rtype: numpy.ndarray """ params = np.empty((num_samples,self.p.size)) - for i in xrange(num_samples): + for i in range(num_samples): self.p[:] = np.random.multivariate_normal(np.zeros(self.p.size),self.M) H_old = self._computeH() theta_old = self.model.optimizer_array.copy() @@ -59,7 +59,7 @@ class HMC: return params def _update(self, hmc_iters): - for i in xrange(hmc_iters): + for i in range(hmc_iters): self.p[:] += -self.stepsize/2.*self.model._transform_gradients(self.model.objective_function_gradients()) self.model.optimizer_array = self.model.optimizer_array + self.stepsize*np.dot(self.Minv, self.p) self.p[:] += -self.stepsize/2.*self.model._transform_gradients(self.model.objective_function_gradients()) @@ -82,7 +82,7 @@ class HMC_shortcut: def sample(self, m_iters=1000, hmc_iters=20): params = np.empty((m_iters,self.p.size)) - for i in xrange(m_iters): + for i in range(m_iters): # sample a stepsize from the uniform distribution stepsize = np.exp(np.random.rand()*(self.stepsize_range[1]-self.stepsize_range[0])+self.stepsize_range[0]) self.p[:] = np.random.multivariate_normal(np.zeros(self.p.size),self.M) diff --git a/GPy/kern/_src/coregionalize.py b/GPy/kern/_src/coregionalize.py index 1b16fd73..5b91de1c 100644 --- a/GPy/kern/_src/coregionalize.py +++ b/GPy/kern/_src/coregionalize.py @@ -166,7 +166,7 @@ class Coregionalize(Kern): def update_gradients_diag(self, dL_dKdiag, X): index = np.asarray(X, dtype=np.int).flatten() - dL_dKdiag_small = np.array([dL_dKdiag[index==i].sum() for i in xrange(self.output_dim)]) + dL_dKdiag_small = np.array([dL_dKdiag[index==i].sum() for i in range(self.output_dim)]) self.W.gradient = 2.*self.W*dL_dKdiag_small[:, None] self.kappa.gradient = dL_dKdiag_small diff --git a/GPy/kern/_src/splitKern.py b/GPy/kern/_src/splitKern.py index 18771cb0..051e492b 100644 --- a/GPy/kern/_src/splitKern.py +++ b/GPy/kern/_src/splitKern.py @@ -104,7 +104,7 @@ class SplitKern(CombinationKernel): assert len(slices2)<=2, 'The Split kernel only support two different indices' target = np.zeros((X.shape[0], X2.shape[0])) # diagonal blocks - [[target.__setitem__((s,s2), self.kern.K(X[s,:],X2[s2,:])) for s,s2 in itertools.product(slices[i], slices2[i])] for i in xrange(min(len(slices),len(slices2)))] + [[target.__setitem__((s,s2), self.kern.K(X[s,:],X2[s2,:])) for s,s2 in itertools.product(slices[i], slices2[i])] for i in range(min(len(slices),len(slices2)))] if len(slices)>1: [target.__setitem__((s,s2), self.kern_cross.K(X[s,:],X2[s2,:])) for s,s2 in itertools.product(slices[1], slices2[0])] if len(slices2)>1: @@ -135,7 +135,7 @@ class SplitKern(CombinationKernel): else: assert dL_dK.shape==(X.shape[0],X2.shape[0]) slices2 = index_to_slices(X2[:,self.index_dim]) - [[collate_grads(dL_dK[s,s2],X[s],X2[s2]) for s,s2 in itertools.product(slices[i], slices2[i])] for i in xrange(min(len(slices),len(slices2)))] + [[collate_grads(dL_dK[s,s2],X[s],X2[s2]) for s,s2 in itertools.product(slices[i], slices2[i])] for i in range(min(len(slices),len(slices2)))] if len(slices)>1: [collate_grads(dL_dK[s,s2], X[s], X2[s2], True) for s,s2 in itertools.product(slices[1], slices2[0])] if len(slices2)>1: diff --git a/GPy/models/ss_gplvm.py b/GPy/models/ss_gplvm.py index a61ad2a0..b8e1c72d 100644 --- a/GPy/models/ss_gplvm.py +++ b/GPy/models/ss_gplvm.py @@ -71,7 +71,7 @@ class SSGPLVM(SparseGP_MPI): self.link_parameter(self.X, index=0) if self.group_spike: - [self.X.gamma[:,i].tie('tieGamma'+str(i)) for i in xrange(self.X.gamma.shape[1])] # Tie columns together + [self.X.gamma[:,i].tie('tieGamma'+str(i)) for i in range(self.X.gamma.shape[1])] # Tie columns together def set_X_gradients(self, X, X_grad): """Set the gradients of the posterior distribution of X in its specific form.""" diff --git a/GPy/models/ss_mrd.py b/GPy/models/ss_mrd.py index 036ac095..bd2efce0 100644 --- a/GPy/models/ss_mrd.py +++ b/GPy/models/ss_mrd.py @@ -19,10 +19,10 @@ class SSMRD(Model): name='model_'+str(i)) for i,y in enumerate(Ylist)] self.add_parameters(*(self.models)) - [[[self.models[m].X.mean[i,j:j+1].tie('mean_'+str(i)+'_'+str(j)) for m in xrange(len(self.models))] for j in xrange(self.models[0].X.mean.shape[1])] - for i in xrange(self.models[0].X.mean.shape[0])] - [[[self.models[m].X.variance[i,j:j+1].tie('var_'+str(i)+'_'+str(j)) for m in xrange(len(self.models))] for j in xrange(self.models[0].X.variance.shape[1])] - for i in xrange(self.models[0].X.variance.shape[0])] + [[[self.models[m].X.mean[i,j:j+1].tie('mean_'+str(i)+'_'+str(j)) for m in range(len(self.models))] for j in range(self.models[0].X.mean.shape[1])] + for i in range(self.models[0].X.mean.shape[0])] + [[[self.models[m].X.variance[i,j:j+1].tie('var_'+str(i)+'_'+str(j)) for m in range(len(self.models))] for j in range(self.models[0].X.variance.shape[1])] + for i in range(self.models[0].X.variance.shape[0])] self.updates = True @@ -31,4 +31,4 @@ class SSMRD(Model): self._log_marginal_likelihood = sum([m._log_marginal_likelihood for m in self.models]) def log_likelihood(self): - return self._log_marginal_likelihood \ No newline at end of file + return self._log_marginal_likelihood diff --git a/GPy/plotting/matplot_dep/img_plots.py b/GPy/plotting/matplot_dep/img_plots.py index 453a904d..5346545d 100644 --- a/GPy/plotting/matplot_dep/img_plots.py +++ b/GPy/plotting/matplot_dep/img_plots.py @@ -50,8 +50,8 @@ def plot_2D_images(figure, arr, symmetric=False, pad=None, zoom=None, mode=None, buf = np.ones((y_size*fig_nrows+pad*(fig_nrows-1), x_size*fig_ncols+pad*(fig_ncols-1), 3),dtype=arr.dtype) - for y in xrange(fig_nrows): - for x in xrange(fig_ncols): + for y in range(fig_nrows): + for x in range(fig_ncols): if y*fig_ncols+x