np.random.seed(int(sys.argv[-1]) + 10) Ds = [1, 12, 64] R, BS = 110, 150 sigma_x = .1 model = networks.create_fns(BS, R, Ds, 1, lr=0.001, leakiness=0.1, var_x=sigma_x**2) DATA = datasets.load_digits(n_class=1).images DATA = DATA[:BS].reshape((BS, -1)) + np.random.randn(BS, Ds[-1]) * 0.1 #DATA -= DATA.mean(1, keepdims=True) DATA /= (DATA.max() * 10) print(DATA) L = [] for iter in tqdm(range(36)): plt_state() plt.savefig('samples_{}.png'.format(iter)) plt.close() L.append(networks.EM(model, DATA, 1, 10, pretrain=iter==0, update_var=iter>5)) print(L[-1]) plt.figure() plt.plot(np.concatenate(L), lw=3) plt.savefig('NLL.png') plt.close()
Ds, 1, lr=0.001, leakiness=args.leakiness, var_x=args.std**2) for RUN in range(20): # do the VAE case if args.model != 'EM': filename = 'nnnnsaving_likelihood_{}_{}_{}_{}_{}_{}.npz' for lr_ in [0.005, 0.001, 0.0001]: graph.reset() lr.update(lr_) out = networks.EM(model, DATA, epochs=args.epochs, n_iter=500, extra=emt) np.savez(filename.format(args.dataset, args.epochs, args.model, lr_, args.network, RUN), L=out[0], LL=out[1], samples=model['sample'](4 * BS), noise=np.random.randn(4 * BS, 2) * np.sqrt(model['varx']()), data=DATA) else: graph.reset() filename = 'nnnsaving_likelihood_{}_{}_{}_{}_{}.npz' out = networks.EM(model, DATA,
plt.subplot(10, 10, 1 + i) plt.imshow(predictions[i].reshape((8, 8))) for i in range(50): plt.subplot(10, 10, 51 + i) plt.imshow(DATA[i].reshape((8, 8))) np.random.seed(int(sys.argv[-1]) + 10) Ds = [1, 20, 64] R, BS = 110, 150 model = networks.create_fns(BS, R, Ds, 0, var_x=np.ones(Ds[-1]), lr=0.001) DATA = datasets.load_digits(n_class=1).images DATA = DATA[:BS].reshape((BS, -1)) DATA /= (0.1 + DATA.max(1, keepdims=True)) DATA -= DATA.mean(1, keepdims=True) DATA += np.random.randn(BS, Ds[-1]) * 0.3 L = [] for iter in tqdm(range(16)): L.append(networks.EM(model, DATA, 100)) plt_state() plt.savefig('samples_{}.png'.format(iter)) plt.close() plt.figure() plt.plot(np.concatenate(L), lw=3) plt.savefig('NLL.png') plt.close()
#DATA = np.vstack([DATA * np.cos(DATA), DATA * np.sin(DATA)]).T DATA += np.random.randn(BS, Ds[-1]) * 0.1 DATA -= DATA.mean(0) DATA /= DATA.max(0) DATA /= 1 #DATA *= 3 #DATA += 2 L = [] for iter in tqdm(range(550)): L.append( networks.EM(model, DATA, 1, min((iter + 1) * 20, 1400), pretrain=iter == args.pretrain, update_var=iter > 1)) # L.append(networks.EM(model, DATA, 1, 1400, pretrain=iter==args.pretrain, update_var=iter>2)) # print(L[-1]) # print(L[-1][0], L[-1][-1]) # X = model['sample'](BS) noise = np.random.randn(*X.shape) * np.sqrt(model['varx']()) plt.figure(figsize=(12, 6)) plt.subplot(121) plt.scatter(DATA[:, 0], DATA[:, 1]) plt.scatter(X[:, 0], X[:, 1]) plt.scatter(X[:, 0] + noise[:, 0], X[:, 1] + noise[:, 1]) plt.subplot(122) plt.plot(np.concatenate(L))