T = 15

plt.ion()
plt.figure(1)
# for i in range(N):
#     ax = plt.subplot2grid((N,2),(i,0))
#     plt.imshow(np.random.randn(D,T),interpolation='none',aspect=T/D,cmap='Greys_r')
#     pltuls.strip_ticks(ax)
#
# plt.text(0.3,0.95,'True W',transform=plt.gcf().transFigure)

#
ims = []
for i in range(N):
    ax = plt.subplot2grid((N, 2), (i, 1))
    im = ax.imshow(np.random.randn(D, T),
                   interpolation='none',
                   aspect=T / D,
                   cmap='Greys_r')
    ims.append(im)
    pltuls.strip_ticks(ax)
# plt.show()

for j in range(100):
    for i in range(N):
        im = ims[i]
        test_im = np.random.randn(D, T)
        im.set_array(test_im)
    plt.draw()
    plt.pause(0.1)
        SS_tot = np.sum(np.square(M_nsy-np.mean(M_nsy)))
        oneminusrsq = SS_res/SS_tot
    print("1 - R^2: "+str(oneminusrsq))
    #Reassign 1 - R^2
    oneminusrsq = 5.

    plt.ion()
    #Plot the true W
    plt.figure(1)
    colormap = matplotlib.cm.get_cmap('Reds')
    for i in range(N):
        ax = plt.subplot2grid((N,3),(i,0))
        plt.imshow(util.normalize(W[:,i].T[:,None]),interpolation='none',
        aspect=3./D,cmap=colormap,vmin=0,vmax=1)
        pltuls.strip_bare(ax,axis='x')
        pltuls.strip_ticks(ax,axis='y')
    plt.text(0.25,0.95,'True W',transform=plt.gcf().transFigure)

    #Initialize synergy estimators
    synergy_estimator = synergy_estimators.SynchronousSynergyEstimator(
        D,T,N,M_nsy)

    #Plot the W_ests
    ims = []
    plt.figure(1)
    for i in range(N):
        ax = plt.subplot2grid((N,3),(i,2))
        im = plt.imshow(synergy_estimator.W_est[:,i].T[
            :,None],interpolation='none',aspect=3./D,
                cmap=colormap,vmin=0,vmax=1)
        pltuls.strip_bare(ax,axis='x')