for i, yi in enumerate(grid_x):
    for j, xi in enumerate(grid_y):
        mani_pos = [0, 1]
        z_sample = np.random.randn(1, latent_dim)
        z_sample[:, mani_pos] = [xi, yi]
        #z_sample = np.array(np.hstack([ [[xi, yi]],np.random.randn(1,latent_dim-2) ]))*1
        w_sample = np.random.randn(1, latent_dim_w) * 1
        # randomize w instead of z as the manifold parameters
        # here we should see a disoriented behaviour
        #z_sample = np.random.randn(1,latent_dim)*1
        #w_sample = np.concatenate([np.array([[xi, yi]]), [np.random.randn(latent_dim_w-2)*1]],axis=1)

        x_decoded = generator.predict([z_sample, w_sample])
        digit = x_decoded[0].reshape(digit_size, digit_size)
        h_est = fbm_data.hurst2d(digit, max_tau=5)
        grad = np.gradient(digit)
        kurt = kurtosis(grad[0][2:-1, 2:-1].flatten())
        #kurt = kurtosis(grad[0][2:-1,2:-1].flatten())
        hh, r2 = h_est
        h_figure[i, j, :] = np.array([hh, r2, kurt])

        hh_entry = int(hh * 10) - 3
        if hh_entry >= 0 and hh_entry < 6:
            example_imgs[:, :, hh_entry] = mat2gray(digit)
            example_imgs_stats[hh_entry, :] = [hh, r2, kurt]

        if hh < 0.5:  # and False:
            plt.hold(False)
            plt.imshow(digit, interpolation='none')
            plt.title('H=%f, R^2=%f' % (hh, r2))
Example #2
0
# to produce values of the latent variables z, since the prior of the latent space is Gaussian
grid_x = norm.ppf(np.linspace(0.05, 0.95, n))
grid_y = norm.ppf(np.linspace(0.05, 0.95, n))
##
for i, yi in enumerate(grid_x):
    for j, xi in enumerate(grid_y):
        z_sample = np.array([[xi, yi]])
        w_sample = np.random.randn(1, latent_dim_w) * 1
        # randomize w instead of z as the manifold parameters
        # here we should see a disoriented behaviour
        #z_sample = np.random.randn(1,latent_dim)*1
        #w_sample = np.concatenate([np.array([[xi, yi]]), [np.random.randn(latent_dim_w-2)*1]],axis=1)

        x_decoded = generator.predict([z_sample, w_sample])
        digit = x_decoded[0].reshape(digit_size, digit_size)
        h_figure[i, j, :] = fbm_data.hurst2d(digit, max_tau=5)
        figure[i * digit_size:(i + 1) * digit_size,
               j * digit_size:(j + 1) * digit_size] = digit

#plt.figure(figsize=(10, 10))
figure = figure - np.min(figure)
figure = figure / np.max(figure)
_, pp = plt.subplots(2, 2)
pp[0, 0].imshow(figure, cmap='gray', interpolation='none')
#.show()
res = pp[0, 1].imshow(h_figure[:, :, 0], cmap='gray', interpolation='none')
plt.colorbar(res, ax=pp[0, 1])
pp[0, 1].set_title('H')
res = pp[1, 0].imshow(h_figure[:, :, 1], cmap='gray', interpolation='none')
plt.colorbar(res, ax=pp[1, 0])
pp[1, 0].set_title('R^2')