예제 #1
0
def BER_NN(codebook,nb_pkts=100):
  e0 = np.logspace(-3, 0, 15)
  e0 = np.concatenate((np.array([0.001]), np.linspace(0.01, 0.1, 10, endpoint=False), np.linspace(0.1, 1, 15)), axis=0)
  e0[len(e0) - 1] = e0[len(e0) - 1] - 0.001
  e1 = [t for t in e0 if t <= 0.5]
  metric = test.read_ber_file(N, k,'BER')
  BER = test.saved_results(metric,N, k)

  BER['dec'],a = utils_ML.bit_error_rate_NN_decoder(N, k, codebook, nb_pkts, e0, e1,model_decoder, 'one', train_epsilon)
  print("metric['dec-NN'] = ",BER['dec'])
  if MAP_test:
    BER['MAP'] = utils.bit_error_rate(k, codebook, nb_pkts, e0, e1)

  test.plot_ber(BER, N,k)
예제 #2
0
def BER_NN(codebook,nb_pkts=100):
  e0 = np.logspace(-3, 0, 15)
  # e0 = np.linspace(0.001, 1, 11)
  e0[len(e0) - 1] = e0[len(e0) - 1] - 0.001
  e1 = [t for t in e0 if t <= 0.5]
  metric = test.read_ber_file(N, k)
  BER = test.saved_results(metric,N, k)

  BER['dec'] = utils.bit_error_rate_NN(N, k, codebook, nb_pkts, e0, e1,channel)
  print("metric['BKLC-NN'] = ",BER['dec'])
  if MAP_test:
    BER['MAP'] = utils.bit_error_rate(k, codebook, nb_pkts, e0, e1)

  test.plot_ber(BER, N,k,e0)
예제 #3
0
def BER_NN(nb_pkts=100):
    # e0 = np.logspace(-3, 0, 15)
    # e0 = np.linspace(0.001, 0.999, 11)
    e0 = np.concatenate(
        (np.linspace(0.001, 0.2, 5, endpoint=False), np.linspace(0.2, 1, 8)),
        axis=0)
    e0[len(e0) - 1] = e0[len(e0) - 1] - 0.001
    e1 = [t for t in e0 if t <= 0.5]

    one_hot = np.eye(2**k)
    print('codebook', model_encoder.predict(one_hot))
    C = np.round(model_encoder.predict(one_hot)).astype('int')
    aux = []
    for code in C.tolist():
        if code not in aux:
            aux.append(code)
    nb_repeated_codes = len(C) - len(aux)
    print('+++++++++++++++++++ Repeated Codes NN encoder = ',
          nb_repeated_codes)
    print('dist = ', sum([sum(codeword) for codeword in C]) * 1.0 / (N * 2**k))
    print('***************************************************************')

    if nb_repeated_codes == 0:
        metric = test.read_ber_file(N, k)
        BER = test.saved_results(metric, N, k)
        print("NN BER")
        t = time.time()
        BER['auto'] = bit_error_rate_NN(N, k, C, nb_pkts, e0, e1, channel)
        t = time.time() - t
        print(f"NN time = {t}s ========================")
        print("metric['BKLC-NN'] = ", BER['auto'])

        if MAP_test:
            print("MAP BER")
            t = time.time()
            BER['MAP'] = utils.bit_error_rate(k, C, nb_pkts, e0, e1)
            t = time.time() - t
            print(f"MAP time = {t}s =======================")

        test.plot_ber(BER, N, k, e0)

    else:
        print('Bad codebook repeated codewords')