fig.suptitle('JS diverence, clustering = all times')
if fig_dir is not None:
    fig.savefig(
        os.path.join(fig_dir, 'JSD_time_clustering_tbins=%d.pdf' % (tbins)))

### Manifold embeddings

reload(fplt)

plt.figure(200)
plt.clf()
#label = range(tbins) * nstrains
#label = list(np.sort(range(nstages) * sbins)) * nstrains
label = np.sort(range(nstrains) * tbins)
res = fplt.plot_manifold_embeddings(ent_t['all'],
                                    precomputed=True,
                                    label=label)

reload(fplt)
fig = plt.figure(50)
plt.clf()
label = np.sort(range(nstrains) * tbins)
colors = ['red', 'blue', 'darkgreen', 'orange', 'purple', 'gray']
cmaps = [
    plt.cm.Reds, plt.cm.Blues, plt.cm.Greens, plt.cm.Oranges, plt.cm.Purples,
    plt.cm.gray_r
]
i = 0
for k, v, in res.iteritems():
    plt.subplot(1, 3, i + 1)
    i += 1
plt.plot(dat_mean)
plt.plot(dat_var)


reload(als)
reload(fplt)

plt.figure(10); plt.clf()
fplt.plot_pca(dist.T)

plt.figure(11); plt.clf();
fplt.plot_nmf(dist.T, n_components=None)

reload(fplt)
plt.figure(20);
fplt.plot_manifold_embeddings(dist.T, n_components=3, n_neighbors=20)
plt.tight_layout()


### Fit distributions

#dist_names = ['gamma', 'beta', 'rayleigh', 'norm', 'pareto'
import scipy;
dist_name = 'beta';

dist_form = getattr(scipy.stats, dist_name)

param = np.zeros((dist_form.numargs + 2, nbins));
eps = 10e-9;
for b in range(1):
  dd = dat_bin[:,b].copy();