def wave_tensor_data_backbone(batch_x, depth=-1, i_ref=-1, j_ref=-1): batch_size, _ = batch_x.shape FLAG_RAND_I = i_ref == -1 FLAG_RAND_J = j_ref == -1 FLAG_DEPTH = depth == -1 wave_tensor = init_wave_tensor(batch_size) for num_batch in range(batch_size): image = mnist_reshape_32(batch_x[num_batch]) w = WaveImage(image=image) if FLAG_RAND_I: i_ref = np.random.randint(16) if FLAG_RAND_J: j_ref = np.random.randint(16) if FLAG_DEPTH: depth = 1 + np.random.randint(6) pow2_i = calc_pow2(i_ref) pow2_j = calc_pow2(j_ref) for h in range(6 - depth, 6): data_h = w.get_data()[h] if h == 0: wave_tensor[h][num_batch][0][0][0] = data_h[(0, 0)] #/ 4**4 else: u = (pow2_i[h - 1], pow2_j[h - 1]) #for u in data_h: # wave_tensor[h][num_batch][u[0]][u[1]][:] = 0 wave_tensor[h][num_batch][u[0]][u[1]][:] = data_h[ u] #/ 4 ** (5 - h) return wave_tensor
def wave_tensor_data_backbone(batch_x, depth=-1, i_ref=-1, j_ref=-1): tab_depth = [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 6] batch_size, _ = batch_x.shape FLAG_RAND_I = i_ref == -1 FLAG_RAND_J = j_ref == -1 FLAG_DEPTH = depth == -1 wave_tensor = init_wave_tensor(batch_size) for num_batch in range(batch_size): image = mnist_reshape_32(batch_x[num_batch]) w = WaveImage(image=image) if FLAG_RAND_I: #i_ref = np.random.randint(16) # RND-PARTS liste_u_full = [] for i in range(16): for j in range(16): liste_u_full += [(i, j)] indices_perm = np.arange(256, dtype='int') np.random.shuffle(indices_perm) nb_u = np.random.randint(256) liste_u_full = np.array(liste_u_full) liste_u = liste_u_full[indices_perm] liste_u = liste_u[:nb_u] if FLAG_RAND_J: #j_ref = np.random.randint(16) pass # RND-PARTS if FLAG_DEPTH: # indice_depth = np.random.randint(21) # depth = tab_depth[indice_depth] # BIASED # depth = 1 + np.random.randint(6) # UNIF # depth = 6 # BASE #indice_depth = np.random.randint(256) #FULL #if indice_depth < 1: # depth = 6 #elif indice_depth < 4: # depth = 4 #elif indice_depth < 16: # depth = 3 #elif indice_depth < 64: # depth = 2 #else: # depth = 1 depth = 6 # RND-PARTS for u in liste_u: i_ref = u[0] j_ref = u[1] pow2_i = calc_pow2(i_ref) pow2_j = calc_pow2(j_ref) for h in range(6 - depth, 6): data_h = w.get_data()[h] if h == 0: wave_tensor[h][num_batch][0][0][0] = data_h[(0, 0)] #/ 4**4 else: u = (pow2_i[h - 1], pow2_j[h - 1]) #for u in data_h: # wave_tensor[h][num_batch][u[0]][u[1]][:] = 0 wave_tensor[h][num_batch][u[0]][u[1]][:] = data_h[ u] #/ 4 ** (5 - h) return wave_tensor
def wave_tensor_data(batch_x): batch_size, _ = batch_x.shape wave_tensor = {} for h in range(6): if h == 0: h_size = 1 wave_tensor[h] = np.zeros((batch_size, h_size, h_size, 1)) else: h_size = 2**(h - 1) wave_tensor[h] = np.zeros((batch_size, h_size, h_size, 3)) for num_batch in range(batch_size): image = mnist_reshape_32(batch_x[num_batch]) w = WaveImage(image=image) for h in range(w.get_h_max()): data_h = w.get_data()[h] if h == 0: wave_tensor[h][num_batch][0][0][0] = data_h[(0, 0)] else: for u in data_h: wave_tensor[h][num_batch][u[0]][u[1]][:] = data_h[u] return wave_tensor
# ## Creation de la base d'apprentissage # In[12]: file_name = "mnist-waveimage-train-mu-Sigma-rho.pkl" if not os.path.isfile(file_name): B_train = [] for i in range(len(mnist.train.images)): if i % 1000 == 0: sys.stdout.write('\rstep %d' % i) sys.stdout.flush() c = mnist.train.labels[i] x_ref = mnist.train.images[i] image = mnist_reshape_32(x_ref) w = WaveImage(image=image) data = w.get_data() for h in range(w.get_h_max()): data_h = w.get_data()[h] for u in data_h: v = data_h[u] B_train += [(v, (c, h, u))] ### Dictionnaire (Base d'apprentissage) Data_train = [[], [], [], [], [], [], [], [], [], []] for c in range(10): Data_train[c] = [{}, {}, {}, {}, {}, {}] for d in B_train: