Nclust = 20 Nx = 12 Nobs = [np.random.randint(20,21) for i in range(Nclust)] X = np.random.rand(Nx,1)*5 X.sort(0) Kf = kern.rbf(1) + kern.white(1, 1e-6) S = Kf.K(X) means = np.vstack([np.tile(np.random.multivariate_normal(np.zeros(Nx),S,1),(N,1)) for N in Nobs]) # GP draws for mean of each cluster #add GP draw for noise Ky = kern.rbf(1,0.3,1) + kern.white(1,0.001) Y = means + np.random.multivariate_normal(np.zeros(Nx),Ky.K(X),means.shape[0]) #construct model m = MOHGP(X, Kf.copy(), Ky.copy(), Y, K=Nclust) m.constrain_positive('') m.optimize() m.preferred_optimizer='bfgs' m.systematic_splits() m.remove_empty_clusters(1e-3) m.plot(1,1,1,0,0,1) raw_input('press enter to continue ...') #and again without structure Y -= Y.mean(1)[:,None] Y /= Y.std(1)[:,None] m2 = MOHGP(X, Kf, kern.white(1), Y, K=Nclust) m2.constrain_positive('') m2.preferred_optimizer='bfgs'
phases = 2*np.pi*np.random.rand(Nclust) means = np.vstack([np.tile(np.sin(f*X+p).T,(Ni,1)) for f,p,Ni in zip(freqs,phases,Nobs)]) #add a lower freq sin for the noise freqs = .4*np.pi + 0.01*(np.random.rand(means.shape[0])-.5) phases = 2*np.pi*np.random.rand(means.shape[0]) offsets = 0.3*np.vstack([np.sin(f*X+p).T for f,p in zip(freqs,phases)]) Y = means + offsets + np.random.randn(*means.shape)*0.05 #construct full model Kf = kern.rbf(1,0.01,0.001) Ky1 = kern.rbf(1,0.1,0.001) Ky2 = kern.white(1,0.01) Ky = Ky1 + Ky2 m = MOHGP(X,Kf,Ky,Y, K=Nclust, prior_Z = 'DP', alpha=alpha) m.ensure_default_constraints() m.checkgrad(verbose=1) m.randomize() m.optimize() m.systematic_splits() m.systematic_splits() m.plot(1,1,1,0,0,1) #construct model without structure #give it a fighting chance by normalising signals first Y = Y.copy() Y -= Y.mean(1)[:,None] Y /= Y.std(1)[:,None] Kf = kern.rbf(1,0.01,0.001)
X.sort(0) Kf = kern.rbf(1) + kern.white(1, 1e-6) S = Kf.K(X) means = np.vstack([ np.tile(np.random.multivariate_normal(np.zeros(Nx), S, 1), (N, 1)) for N in Nobs ]) # GP draws for mean of each cluster #add GP draw for noise Ky = kern.rbf(1, 0.3, 1) + kern.white(1, 0.001) Y = means + np.random.multivariate_normal(np.zeros(Nx), Ky.K(X), means.shape[0]) #construct model m = MOHGP(X, Kf.copy(), Ky.copy(), Y, K=Nclust) m.constrain_positive('') m.optimize() m.preferred_optimizer = 'bfgs' m.systematic_splits() m.remove_empty_clusters(1e-3) m.plot(1, 1, 1, 0, 0, 1) raw_input('press enter to continue ...') #and again without structure Y -= Y.mean(1)[:, None] Y /= Y.std(1)[:, None] m2 = MOHGP(X, Kf, kern.white(1), Y, K=Nclust) m2.constrain_positive('') m2.preferred_optimizer = 'bfgs'
np.tile(np.sin(f * X + p).T, (Ni, 1)) for f, p, Ni in zip(freqs, phases, Nobs) ]) #add a lower freq sin for the noise freqs = .4 * np.pi + 0.01 * (np.random.rand(means.shape[0]) - .5) phases = 2 * np.pi * np.random.rand(means.shape[0]) offsets = 0.3 * np.vstack([np.sin(f * X + p).T for f, p in zip(freqs, phases)]) Y = means + offsets + np.random.randn(*means.shape) * 0.05 #construct full model Kf = kern.rbf(1, 0.01, 0.001) Ky1 = kern.rbf(1, 0.1, 0.001) Ky2 = kern.white(1, 0.01) Ky = Ky1 + Ky2 m = MOHGP(X, Kf, Ky, Y, K=Nclust, prior_Z='DP', alpha=alpha) m.ensure_default_constraints() m.checkgrad(verbose=1) m.randomize() m.optimize() m.systematic_splits() m.systematic_splits() m.plot(1, 1, 1, 0, 0, 1) #construct model without structure #give it a fighting chance by normalising signals first Y = Y.copy() Y -= Y.mean(1)[:, None] Y /= Y.std(1)[:, None] Kf = kern.rbf(1, 0.01, 0.001)