def main(root, pattern='*'): bins = np.logspace(-4, 2, 127) for t in lmj.cubes.Experiment(root).trials_matching(pattern): stats, jac = t.jacobian(10, markers=MARKERS) plt.colorbar(plt.imshow(jac.values[500:800].T, vmin=-1, vmax=1, cmap='coolwarm')) plt.show() hist = np.zeros((len(jac), len(bins)), float) for t, j in enumerate(jac.values): for i in bins.searchsorted(abs(j)): hist[t, i-1] += 1 plt.colorbar(plt.imshow(hist[500:800, :-1].T, cmap='coolwarm')) plt.show()
def main(root, pattern='*'): bins = np.logspace(-4, 2, 127) for t in lmj.cubes.Experiment(root).trials_matching(pattern): stats, jac = t.jacobian(10, markers=MARKERS) plt.colorbar( plt.imshow(jac.values[500:800].T, vmin=-1, vmax=1, cmap='coolwarm')) plt.show() hist = np.zeros((len(jac), len(bins)), float) for t, j in enumerate(jac.values): for i in bins.searchsorted(abs(j)): hist[t, i - 1] += 1 plt.colorbar(plt.imshow(hist[500:800, :-1].T, cmap='coolwarm')) plt.show()
def main(args): data = np.load(args.dataset, mmap_mode='r') N = data.shape[1] T = args.frames K = int(N * T * args.overcomplete) def batches(): batch = np.zeros((args.batch_size, N * T), 'f') for b in range(args.batch_size): o = np.random.randint(len(data) - T - 1) batch[b] = data[o:o+T].ravel() return [batch] net = theanets.Autoencoder([N * T, (K, 'linear'), (N * T, 'tied')]) net.train(batches, monitors={'hid1:out': (-0.1, -0.01, 0.01, 0.1)}, **models.kwargs_from_args(args)) D = net.find('hid1', 'w').get_value().T R = 6 C = 18 dimg = np.zeros((R * (N + 1) - 1, C * (T + 1) - 1), float) bimg = np.zeros((R * (N + 1) - 1, C * (T + 1) - 1), float) idx = abs(D).max(axis=1).argsort()[::-1] for r in range(R): for c in range(C): o = np.random.randint(len(data) - T - 1) dimg[r*(N+1):r*(N+1)+N, c*(T+1):c*(T+1)+T] = data[o:o+T].T bimg[r*(N+1):r*(N+1)+N, c*(T+1):c*(T+1)+T] = D[idx[r * C + c]].reshape((T, N)).T _, (dax, bax) = plt.subplots(1, 2) dax.imshow(dimg, cmap='coolwarm') sns.despine(ax=dax, left=True, bottom=True) dax.set_xticks([]) dax.set_yticks([]) bax.imshow(bimg, cmap='coolwarm') sns.despine(ax=bax, left=True, bottom=True) bax.set_xticks([]) bax.set_yticks([]) plt.show() logging.info('%s: saving %s %s', args.codebook, D.shape, D.dtype) np.save(args.codebook, D)