mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-07 19:12:40 +02:00
Various Py3 fixes
This commit is contained in:
parent
273beca272
commit
6d2393ae90
4 changed files with 14 additions and 14 deletions
|
|
@ -414,7 +414,7 @@ class DGPLVM_KFDA(Prior):
|
||||||
def compute_cls(self, x):
|
def compute_cls(self, x):
|
||||||
cls = {}
|
cls = {}
|
||||||
# Appending each data point to its proper class
|
# Appending each data point to its proper class
|
||||||
for j in xrange(self.datanum):
|
for j in range(self.datanum):
|
||||||
class_label = self.get_class_label(self.lbl[j])
|
class_label = self.get_class_label(self.lbl[j])
|
||||||
if class_label not in cls:
|
if class_label not in cls:
|
||||||
cls[class_label] = []
|
cls[class_label] = []
|
||||||
|
|
@ -553,7 +553,7 @@ class DGPLVM(Prior):
|
||||||
def compute_cls(self, x):
|
def compute_cls(self, x):
|
||||||
cls = {}
|
cls = {}
|
||||||
# Appending each data point to its proper class
|
# Appending each data point to its proper class
|
||||||
for j in xrange(self.datanum):
|
for j in range(self.datanum):
|
||||||
class_label = self.get_class_label(self.lbl[j])
|
class_label = self.get_class_label(self.lbl[j])
|
||||||
if class_label not in cls:
|
if class_label not in cls:
|
||||||
cls[class_label] = []
|
cls[class_label] = []
|
||||||
|
|
@ -572,7 +572,7 @@ class DGPLVM(Prior):
|
||||||
# Adding data points as tuple to the dictionary so that we can access indices
|
# Adding data points as tuple to the dictionary so that we can access indices
|
||||||
def compute_indices(self, x):
|
def compute_indices(self, x):
|
||||||
data_idx = {}
|
data_idx = {}
|
||||||
for j in xrange(self.datanum):
|
for j in range(self.datanum):
|
||||||
class_label = self.get_class_label(self.lbl[j])
|
class_label = self.get_class_label(self.lbl[j])
|
||||||
if class_label not in data_idx:
|
if class_label not in data_idx:
|
||||||
data_idx[class_label] = []
|
data_idx[class_label] = []
|
||||||
|
|
@ -591,7 +591,7 @@ class DGPLVM(Prior):
|
||||||
else:
|
else:
|
||||||
lst_idx = []
|
lst_idx = []
|
||||||
# Here we put indices of each class in to the list called lst_idx_all
|
# Here we put indices of each class in to the list called lst_idx_all
|
||||||
for m in xrange(len(data_idx[i])):
|
for m in range(len(data_idx[i])):
|
||||||
lst_idx.append(data_idx[i][m][0])
|
lst_idx.append(data_idx[i][m][0])
|
||||||
lst_idx_all.append(lst_idx)
|
lst_idx_all.append(lst_idx)
|
||||||
return lst_idx_all
|
return lst_idx_all
|
||||||
|
|
@ -627,7 +627,7 @@ class DGPLVM(Prior):
|
||||||
# pdb.set_trace()
|
# pdb.set_trace()
|
||||||
# Calculating Bi
|
# Calculating Bi
|
||||||
B_i[i] = (M_i[i] - M_0).reshape(1, self.dim)
|
B_i[i] = (M_i[i] - M_0).reshape(1, self.dim)
|
||||||
for k in xrange(self.datanum):
|
for k in range(self.datanum):
|
||||||
for i in data_idx:
|
for i in data_idx:
|
||||||
N_i = float(len(data_idx[i]))
|
N_i = float(len(data_idx[i]))
|
||||||
if k in lst_idx_all[i]:
|
if k in lst_idx_all[i]:
|
||||||
|
|
@ -772,7 +772,7 @@ class DGPLVM_T(Prior):
|
||||||
def compute_cls(self, x):
|
def compute_cls(self, x):
|
||||||
cls = {}
|
cls = {}
|
||||||
# Appending each data point to its proper class
|
# Appending each data point to its proper class
|
||||||
for j in xrange(self.datanum):
|
for j in range(self.datanum):
|
||||||
class_label = self.get_class_label(self.lbl[j])
|
class_label = self.get_class_label(self.lbl[j])
|
||||||
if class_label not in cls:
|
if class_label not in cls:
|
||||||
cls[class_label] = []
|
cls[class_label] = []
|
||||||
|
|
@ -791,7 +791,7 @@ class DGPLVM_T(Prior):
|
||||||
# Adding data points as tuple to the dictionary so that we can access indices
|
# Adding data points as tuple to the dictionary so that we can access indices
|
||||||
def compute_indices(self, x):
|
def compute_indices(self, x):
|
||||||
data_idx = {}
|
data_idx = {}
|
||||||
for j in xrange(self.datanum):
|
for j in range(self.datanum):
|
||||||
class_label = self.get_class_label(self.lbl[j])
|
class_label = self.get_class_label(self.lbl[j])
|
||||||
if class_label not in data_idx:
|
if class_label not in data_idx:
|
||||||
data_idx[class_label] = []
|
data_idx[class_label] = []
|
||||||
|
|
@ -810,7 +810,7 @@ class DGPLVM_T(Prior):
|
||||||
else:
|
else:
|
||||||
lst_idx = []
|
lst_idx = []
|
||||||
# Here we put indices of each class in to the list called lst_idx_all
|
# Here we put indices of each class in to the list called lst_idx_all
|
||||||
for m in xrange(len(data_idx[i])):
|
for m in range(len(data_idx[i])):
|
||||||
lst_idx.append(data_idx[i][m][0])
|
lst_idx.append(data_idx[i][m][0])
|
||||||
lst_idx_all.append(lst_idx)
|
lst_idx_all.append(lst_idx)
|
||||||
return lst_idx_all
|
return lst_idx_all
|
||||||
|
|
@ -846,7 +846,7 @@ class DGPLVM_T(Prior):
|
||||||
# pdb.set_trace()
|
# pdb.set_trace()
|
||||||
# Calculating Bi
|
# Calculating Bi
|
||||||
B_i[i] = (M_i[i] - M_0).reshape(1, self.dim)
|
B_i[i] = (M_i[i] - M_0).reshape(1, self.dim)
|
||||||
for k in xrange(self.datanum):
|
for k in range(self.datanum):
|
||||||
for i in data_idx:
|
for i in data_idx:
|
||||||
N_i = float(len(data_idx[i]))
|
N_i = float(len(data_idx[i]))
|
||||||
if k in lst_idx_all[i]:
|
if k in lst_idx_all[i]:
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ class SparseGPMissing(StochasticStorage):
|
||||||
Thus, we can just make sure the loop goes over self.d every
|
Thus, we can just make sure the loop goes over self.d every
|
||||||
time.
|
time.
|
||||||
"""
|
"""
|
||||||
self.d = xrange(model.Y_normalized.shape[1])
|
self.d = range(model.Y_normalized.shape[1])
|
||||||
|
|
||||||
class SparseGPStochastics(StochasticStorage):
|
class SparseGPStochastics(StochasticStorage):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -165,7 +165,7 @@ class Add(CombinationKernel):
|
||||||
else:
|
else:
|
||||||
eff_dL_dpsi1 += dL_dpsi2.sum(0) * p2.psi1(Z, variational_posterior) * 2.
|
eff_dL_dpsi1 += dL_dpsi2.sum(0) * p2.psi1(Z, variational_posterior) * 2.
|
||||||
grads = p1.gradients_qX_expectations(dL_dpsi0, eff_dL_dpsi1, dL_dpsi2, Z, variational_posterior)
|
grads = p1.gradients_qX_expectations(dL_dpsi0, eff_dL_dpsi1, dL_dpsi2, Z, variational_posterior)
|
||||||
[np.add(target_grads[i],grads[i],target_grads[i]) for i in xrange(len(grads))]
|
[np.add(target_grads[i],grads[i],target_grads[i]) for i in range(len(grads))]
|
||||||
return target_grads
|
return target_grads
|
||||||
|
|
||||||
def add(self, other):
|
def add(self, other):
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ class SparseGPMiniBatch(SparseGP):
|
||||||
m_f = lambda i: "Precomputing Y for missing data: {: >7.2%}".format(float(i+1)/overall)
|
m_f = lambda i: "Precomputing Y for missing data: {: >7.2%}".format(float(i+1)/overall)
|
||||||
message = m_f(-1)
|
message = m_f(-1)
|
||||||
print(message, end=' ')
|
print(message, end=' ')
|
||||||
for d in xrange(overall):
|
for d in range(overall):
|
||||||
self.Ylist.append(self.Y_normalized[self.ninan[:, d], d][:, None])
|
self.Ylist.append(self.Y_normalized[self.ninan[:, d], d][:, None])
|
||||||
print(' '*(len(message)+1) + '\r', end=' ')
|
print(' '*(len(message)+1) + '\r', end=' ')
|
||||||
message = m_f(d)
|
message = m_f(d)
|
||||||
|
|
@ -182,11 +182,11 @@ class SparseGPMiniBatch(SparseGP):
|
||||||
full_values[key][value_indices[key]] += current_values[key]
|
full_values[key][value_indices[key]] += current_values[key]
|
||||||
"""
|
"""
|
||||||
for key in current_values.keys():
|
for key in current_values.keys():
|
||||||
if value_indices is not None and value_indices.has_key(key):
|
if value_indices is not None and key in value_indices:
|
||||||
index = value_indices[key]
|
index = value_indices[key]
|
||||||
else:
|
else:
|
||||||
index = slice(None)
|
index = slice(None)
|
||||||
if full_values.has_key(key):
|
if key in full_values:
|
||||||
full_values[key][index] += current_values[key]
|
full_values[key][index] += current_values[key]
|
||||||
else:
|
else:
|
||||||
full_values[key] = current_values[key]
|
full_values[key] = current_values[key]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue