コード例 #1
0
def polar_codes_mapping(metric, N=8, k=4, nb_pkts = 100, graph = 'BER',channel='BSC'):
  print('-------------------Polar Codes + Mapping-----------------------------')
  cont = 2
  if channel == 'AWGN':
    design_parameter = np.linspace(0.0, 10, cont)
  else:
    design_parameter = np.linspace(0.0001, 0.1, cont)

  for key in [0.5]:
    e_design = 0.1
    # print('===============Design================',key)
    G,infoBits = polar.polar_generator_matrix(64, k, channel, e_design)

    k = len(G)
    Nt = len(G[1])
    t = int(Nt /N)
    U_k = utils.symbols_generator(k)  # all possible messages
    X_m = utils.symbols_generator(t)  # all possible symbol sequences
    C = utils.matrix_codes(U_k, k, G, Nt)

    nx = 2**t*key
    # print('nx', nx, 't', t)
    x = utils.mapping2(C, X_m, t, nx)
    N = len(x[1])
    if graph == 'BLER':
      metric[f"P({e_design})+M({key})"] = utils.block_error_probability(N,k,x,e0,e1)
    else:
      metric[f"P({e_design})+M({key})"] = utils.bit_error_rate(k,x,nb_pkts,e0,e1)
コード例 #2
0
def polar_codes(metric, N=8, k=4, nb_pkts = 100, graph = 'BER',channel='BSC'):
  print('-------------------Polar Code-----------------------------')
  for key in [0.1]:
    G, infoBits = polar.polar_generator_matrix(N,k, channel, key)
    k = len(G)
    N = len(G[1])
    U_k = utils.symbols_generator(k)  # all possible messages
    C = utils.matrix_codes(U_k, k, G, N)
    # print('Polar codebook', np.array(C))
    if graph == 'BLER':
      metric[f"Polar({key})"] = utils.block_error_probability(N,k,C,e0,e1)
    else:
      metric[f"Polar({key})"] = utils.bit_error_rate(k,C,nb_pkts,e0,e1)
    print(metric[f"Polar({key})"])
コード例 #3
0
def polar_codes_NN(metric, N=8, k=4, nb_pkts = 100, graph = 'BER',channel='BSC'):
  print('-------------------Polar Code + NN decoder -----------------------------')
  key = 'NN_dec'
  G,infoBits = polar.polar_generator_matrix(N, k, channel, 0.1)
  # print('G = ', np.array(G))
  k = len(G)
  N = len(G[1])
  U_k = utils.symbols_generator(k)  # all possible messages
  C = utils.matrix_codes(U_k, k, G, N)
  print('k ', k, 'N ', N)
  if graph == 'BLER':
    metric[key] = utils.block_error_probability(N, k, C, e0, e1)
  else:
    metric[key] = utils.bit_error_rate_NN(N, k, C, nb_pkts, e0, e1, channel)
コード例 #4
0
def bch_codes(metric, N=8, k=4, nb_pkts = 100, graph = 'BER'):
  print('-------------------BCH Code-----------------------------')
  G = mat_gen.matrix_codes(N, k, 'bch')
  if G != []:
    for key in [0]:
      # print('G = ', np.array(G))
      k = len(G)
      N = len(G[1])
      U_k = utils.symbols_generator(k)  # all possible messages
      C = utils.matrix_codes(U_k, k, G, N)
      print('k ',k,'N ',N)
      if graph == 'BLER':
        metric[f"BCH({key})"] = utils.block_error_probability(N,k,C,e0,e1)
      else:
        metric[f"BCH({key})"] = utils.bit_error_rate(k,C,nb_pkts,e0,e1)
コード例 #5
0
def linear_codes(metric, N=8, k=4, nb_pkts=100, graph='BER'):
    print('-------------------Linear Code-----------------------------')
    for key in ['BKLC']:
        print(key)
        G = mat_gen.matrix_codes(N, k, key)
        if G != []:
            # print('G = ', np.array(G))
            k = len(G)
            N = len(G[1])
            U_k = utils.symbols_generator(k)  # all possible messages
            C = utils.matrix_codes(U_k, k, G, N)
            print(np.array(C))
            print('k ', k, 'N ', N)
            if graph == 'BLER':
                metric[key] = utils.block_error_probability(N, k, C, e0, e1)
            else:
                metric[key] = utils.bit_error_rate(k, C, nb_pkts, e0, e1)
コード例 #6
0
def linear_codes_mapping(metric, N=8, k=4, nb_pkts = 100, graph = 'BER'):
  print('-------------------Linear Code + Mapping-----------------------------')
  G = mat_gen.matrix_codes(64,k,'linear')
  if G!= []:
    for key in [0.55]:
      k = len(G)
      Nt = len(G[1])
      t = int(Nt/N)
      U_k= utils.symbols_generator(k)  # all possible messages
      X_m = utils.symbols_generator(t)  # all possible symbol sequences
      C = utils.matrix_codes(U_k, k, G, Nt)
      nx = 2**t*key
      # print('nx', nx, 't', t)
      x = utils.mapping(C, X_m, t, nx) #codebook after mapping
      N = len(x[1])

      if graph == 'BLER':
        metric[f"L+M({key})"] = utils.block_error_probability(N,k,x,e0,e1)
      else:
        metric[f"L+M({key})"] = utils.bit_error_rate(k,x,nb_pkts,e0,e1)
コード例 #7
0
       [0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0],
       [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1],
       [0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0],
       [0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1],
       [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1]]

k = len(G)      #Nombre de bits � envoyer
N = len(G[1])   #codeword length

rep = 500
train_epsilon = 0.07
S = 3

################### Coding
U_k = utils.symbols_generator(k)  # all possible messages
cn = utils.matrix_codes(U_k, k, G, N)
# print('codebook',np.array(cn))
print('size C: ',len(cn), 'size Cn: ', len(cn[0]))
c = np.array(cn)
print(type(c[0]))

In = np.eye(2**k) # List of outputs of NN
c = np.tile(c,(rep,1))
In = np.tile(In,(rep,1))
print('size C: ',len(c), 'size Cn: ', len(c[0]))
batch_size = len(In)

########### Neural Network Generator ###################
optimizer = 'adam'
loss = 'categorical_crossentropy'                # or 'mse'
コード例 #8
0
#Parameters
epsilon_test = [0.01, 0.1, 0.3, 0.55]
loss_weights = [0.0, 1.0, 0.0, 0.0, 0.0, 0.0]
MAP_test = True
pretraining = True
train_epsilon_1 = 0.002  #useless for the BSC and epsilon_1 for the BAC
pretrain_epsilon = 0.1
encoder_epsilon = 0.1
decoder_epsilon = 0.1

#Training Data set
u_k = utils.symbols_generator(k)
U_k = np.tile(u_k, (rep, 1))
G, infoBits = utils.polar_generator_matrix(N, k, channel, 0.1)
c_n = utils.matrix_codes(u_k, k, G, N)
C_n = np.tile(np.array(c_n), (rep, 1))

#Hyper parameters
batch_size = 256
initializer = tf.keras.initializers.HeNormal
loss = 'mse'  #'categorical_crossentropy'  #'kl_divergence'
activation = 'relu'

lr = 0.001
decay = 0.999
# reducing the learning rate every epoch
cbks = [LearningRateScheduler(lambda epoch: lr * decay**epoch)]
optimizer = keras.optimizers.Nadam(lr=lr)
lr_metric = utils_ML.get_lr_metric(optimizer)