swiss_roll example

This commit is contained in:
Max Zwiessele 2013-05-14 11:47:19 +01:00
parent a0df861e8c
commit d6c790ae9c
3 changed files with 19 additions and 18 deletions

View file

@ -87,19 +87,19 @@ class Bayesian_GPLVM(sparse_GP, GPLVM):
return x
def _set_params(self, x, save_old=True, save_count=0):
try:
# try:
N, Q = self.N, self.Q
self.X = x[:self.X.size].reshape(N, Q).copy()
self.X_variance = x[(N * Q):(2 * N * Q)].reshape(N, Q).copy()
sparse_GP._set_params(self, x[(2 * N * Q):])
self.oldps = x
except (LinAlgError, FloatingPointError, ZeroDivisionError):
print "\rWARNING: Caught LinAlgError, continueing without setting "
if self._debug:
self._savederrors.append(self.f_call)
if save_count > 10:
raise
self._set_params(self.oldps[-1], save_old=False, save_count=save_count + 1)
# self.oldps = x
# except (LinAlgError, FloatingPointError, ZeroDivisionError):
# print "\rWARNING: Caught LinAlgError, continueing without setting "
# if self._debug:
# self._savederrors.append(self.f_call)
# if save_count > 10:
# raise
# self._set_params(self.oldps[-1], save_old=False, save_count=save_count + 1)
def dKL_dmuS(self):
dKL_dS = (1. - (1. / (self.X_variance))) * 0.5

View file

@ -93,7 +93,7 @@ class MRD(model):
self.NQ = self.N * self.Q
self.MQ = self.M * self.Q
model.__init__(self) # @UndefinedVariable
model.__init__(self) # @UndefinedVariable
@property
def X(self):
@ -255,7 +255,7 @@ class MRD(model):
X[:, qs] = PCA(Y, len(qs))[0]
elif init in "PCA_concat":
X = PCA(numpy.hstack(Ylist), self.Q)[0]
else: # init == 'random':
else: # init == 'random':
X = numpy.random.randn(Ylist[0].shape[0], self.Q)
self.X = X
return X

View file

@ -102,9 +102,10 @@ def swiss_roll_1000():
Y = mat_data['X_data'][:, 0:1000].transpose()
return {'Y': Y, 'info': "Subsample of the swiss roll data extracting only the first 1000 values."}
def swiss_roll():
def swiss_roll(N=3000):
mat_data = scipy.io.loadmat(os.path.join(data_path, 'swiss_roll_data.mat'))
Y = mat_data['X_data'][:, 0:3000].transpose()
Y = mat_data['X_data'][:, 0:N].transpose()
import ipdb;ipdb.set_trace()
return {'Y': Y, 'info': "The first 3,000 points from the swiss roll data of Tennenbaum, de Silva and Langford (2001)."}
def toy_rbf_1d(seed=default_seed):
@ -270,13 +271,13 @@ def cmu_mocap(subject, train_motions, test_motions=[], sample_every=4):
end_ind = 0
for i in range(len(temp_Y)):
start_ind = end_ind
start_ind = end_ind
end_ind += temp_Y[i].shape[0]
Y[start_ind:end_ind, :] = temp_Y[i]
lbls[start_ind:end_ind, :] = temp_lbls[i]
if len(test_motions)>0:
if len(test_motions) > 0:
temp_Ytest = []
temp_lblstest = []
temp_lblstest = []
testexlbls = np.eye(len(test_motions))
tot_test_length = 0
@ -292,7 +293,7 @@ def cmu_mocap(subject, train_motions, test_motions=[], sample_every=4):
end_ind = 0
for i in range(len(temp_Ytest)):
start_ind = end_ind
start_ind = end_ind
end_ind += temp_Ytest[i].shape[0]
Ytest[start_ind:end_ind, :] = temp_Ytest[i]
lblstest[start_ind:end_ind, :] = temp_lblstest[i]
@ -304,7 +305,7 @@ def cmu_mocap(subject, train_motions, test_motions=[], sample_every=4):
for motion in train_motions:
info += motion + ', '
info = info[:-2]
if len(test_motions)>0:
if len(test_motions) > 0:
info += '. Test motions: '
for motion in test_motions:
info += motion + ', '