Exemple #1
0
def disp(net, save_dir, image_history, out_history, energy_history):
    image_history = np.array(image_history).transpose(1, 0, 2, 3, 4, 5).sum(3)
    cplx_image_history = image_history[:, :, 0,
                                       ...] + 1j * image_history[:, :, 1, ...]
    energy_history = np.array(energy_history)
    out_history = np.array(out_history)

    plt.plot(energy_history)
    plt.savefig(os.path.join(save_dir, 'energy.png'))
    plt.close()

    #mean_region_angles = []
    #for r in range(num_regions):
    #    mean_region_angles.append(np.angle(cplx_image_history[:,:,:,r*5:(r+1)*5]).mean((2,3)))
    #mean_region_angles = np.array(mean_region_angles)
    #pairwise_diffs = np.sin(.5*(np.expand_dims(mean_region_angles,0) - np.expand_dims(mean_region_angles,1))).mean(2)
    #pd_means = pairwise_diffs.mean((0,1))
    #pd_std = pairwise_diffs.std((0,1))
    #time = np.arange(len(pd_means))
    #plt.plot(time,pd_means, 'k', color='#3F7F4C')
    #plt.fill_between(time, pd_means - pd_std, pd_means + pd_std, edgecolor='#3F7F4C',facecolor='#7EFF99')
    #plt.savefig(os.path.join(save_dir, 'bar_coherence.png'))
    #plt.close()

    cplx_image_history = image_history[:, :, 0,
                                       ...] + 1j * image_history[:, :, 1, ...]
    save_cplx_anim(os.path.join(save_dir, 'visible'),
                   cplx_image_history,
                   type='gif',
                   number=image_history.shape[1])
Exemple #2
0
    def run(self, sample=False):
        clamp = self.clamped_stimulus if self.clamp else np.ones(num_units)
        x = clamp * np.exp(1j * 2 * np.pi * np.random.rand(self.num_units))
        coherence = []
        x_run = [x]
        for t in range(self.num_steps):
            x = self.step(x, sample=sample)
            coherence.append(np.abs(np.mean(x)))
            x_run.append(x)
            self.current_T *= self.rate_T
            self.current_T = min(self.current_T, self.min_T)
        return np.array(coherence), np.array(x_run)


if __name__ == '__main__':
    num_units = 625
    num_steps = 100
    rn = reichert_net(num_units,
                      num_steps=num_steps,
                      drive_weight=.5,
                      weights='covariance',
                      clamp=False)

    ch, xr = rn.run(sample=False)
    xr = np.expand_dims(xr.reshape(num_steps + 1, 25, 25), 0)

    plt.plot(ch)
    plt.savefig('/home/jk/matt/coherence.png')
    print('Maing videos...')
    save_cplx_anim('/home/jk/matt/xrun', xr)
Exemple #3
0
        for i in range(self.n_gibbs):
            print('Iteration {}'.format(i))
            hidden_activations = self.x_in(self.v_run[i - 1])
            hidden_samples = self.sample(hidden_activations, 'hidden')
            self.h_run.append(hidden_samples)
            visible_activations = self.x_out(self.h_run[i + 1])
            visible_samples = self.sample(visible_activations, 'visible')
            self.v_run.append(visible_samples)

        return self.v_run, self.h_run


net = my_net(in_shape=44,
             weights=[1.0, 1.0, 1.0],
             stride=1,
             style='reichert',
             n_gibbs=64,
             sigma=2.5,
             bias=7.5,
             center_filters=True)
clamp = generate_shape_img(20, 20, pad_width=12)
v, h = net.run(np.squeeze(clamp))
v = np.array(v)
v = np.expand_dims(v, -1)
v = np.expand_dims(v, 0)
h = np.array(h)
h = np.transpose(h, axes=(1, 0, 2, 3))
save_cplx_anim('/home/matt/v', v)
save_cplx_anim('/home/matt/h', h, number=3)
print('done')
Exemple #4
0
#clamp[self.mid,:] = np.exp(1j*0)
#clamp[:,self.mid] = np.exp(1j*np.pi)
#clamp = clamp.astype(np.complex64)
#clamp[self.mid,self.mid] = np.exp(1j*np.pi * .75)
all_cphase = []
all_uphase = []
all_ophase = []
for i in range(50):
    cv, ch = centered_net.run()
    uv, uh = uncentered_net.run()
    ov, oh = other_net.run()
    cv = np.array(cv)
    cv = np.expand_dims(cv, -1)
    cv = np.expand_dims(cv, 0)
    cv[0,:,0,-2:,0] = np.array(ch)
    save_cplx_anim('/home/matt/v', cv)
    ipdb.set_trace()

    cphase_differences = [ np.abs(np.mean(np.angle(vis[mid,:])) - np.mean(np.angle(vis[:,mid]))) for vis in cv]
    uphase_differences = [ np.abs(np.mean(np.angle(vis[mid,:])) - np.mean(np.angle(vis[:,mid]))) for vis in uv]
    ophase_differences = [ np.abs(np.mean(np.angle(vis[mid,:])) - np.mean(np.angle(vis[:,mid]))) for vis in ov]

    all_cphase.append(cphase_differences)
    all_uphase.append(uphase_differences)
    all_ophase.append(ophase_differences)

all_cphase = np.array(all_cphase)
all_uphase = np.array(all_uphase)
all_ophase = np.array(all_ophase)
#PLOT
mean_cphase = np.mean(all_cphase, axis=0)
Exemple #5
0
num_trials = 25
for t in range(num_trials):
    per_trial_phase_diffs = []
    print('Trial {}'.format(t))
    for i in range(im_size):
        stim = np.zeros((im_size, im_size))
        stim[:int(im_size / 2.0), i] = 1.0
        stim[int(im_size / 2.0):, -1*(i+1)] = 1.0
	stim = np.pad(stim, ((pad_size, pad_size),(pad_size, pad_size)), 'constant')
        #stim[:,4] = 1.0
        v, h, p= net.run(stim)
        v, h = np.array(v), np.array(h)
        h = h[:,0,:,:]
        v  = np.expand_dims(np.expand_dims(v,0),-1)
        h = np.expand_dims(np.expand_dims(h,0),-1)
        save_cplx_anim('/home/matt/geman_style_videos/v{}'.format(i), v)
        save_cplx_anim('/home/matt/geman_style_videos/h{}'.format(i),h, number=1)
        final_phase_1 = np.mean(np.angle(v[-1][:int(im_size / 2.0), i]))
        final_phase_2 = np.mean(np.angle(v[-1][int(im_size / 2.0):, -1*(i + 1)]))
        per_trial_phase_diffs.append(np.abs(final_phase_1 - final_phase_2))
    ipdb.set_trace()
    phase_diffs.append(per_trial_phase_diffs)
x = np.array([im_size - 1 - 2*j for j in range(im_size)])
phase_diffs = np.array(phase_diffs)
mean_phase_diffs = np.mean(phase_diffs, axis=0)
std_phase_diffs  = np.std(phase_diffs, axis=0)
plt.plot(x, np.array(mean_phase_diffs), color='#CC4F1B')
plt.fill_between(x, mean_phase_diffs - std_phase_diffs, mean_phase_diffs + std_phase_diffs, edgecolor='#CC4F1B', facecolor='#FF9848')
plt.ylim([0,2*np.pi])
plt.title('Bar phase difference at convergence')
plt.savefig('/home/matt/geman_style_videos/phase_diffs.png')