Beispiel #1
0
def test_pms_err_prob_against_tranx_rate(sequence, Px):
    code_length = 36
    seq = sequence[:code_length]
    sample_size = 500
    error_probability = [i / 1000 for i in range(1, 51)]
    tranx_rate = []
    for Pe in error_probability:
        rate = []
        for i in range(sample_size):
            pms = PMS(Px, Pe)
            s, v, u = pms.transmit(seq, max_channel_use=500)
            if s == seq:
                rate.append(code_length / u)
        tranx_rate.append(sum(rate) / len(rate))
    capacity = BSC_capacity(Px)

    # plot
    x = np.array(error_probability)
    y = tranx_rate
    x_max = max(error_probability)
    plt.plot(x, y, label="tranx rate")
    plt.hlines(capacity, 0, x_max, colors="coral", label="capacity")
    plt.xlim([0, x_max])
    plt.xlabel("Error Probability")
    plt.ylabel("Transmission rate")
    plt.title("Length={}, Px={}, size={}".format(code_length, Px, sample_size))
    plt.legend(loc='lower right')
    plt.savefig(os.path.join("graph", "pms_Pe_tranx_rate.png"))
    plt.show()
Beispiel #2
0
def test_pms_len_against_tranx_rate(Px, Pe, cmt):
    """ Plot message length against transmission rate, write log file
    
    This function will record average transmission rate and channel use for
    each message length. Existent log file will be overwritten. 
    """

    min_code_len = 1
    max_code_len = 40
    sample_size = 700
    tranx_rate = np.zeros(max_code_len - min_code_len + 1)
    channel_use = np.zeros(max_code_len - min_code_len + 1)
    for l in range(min_code_len, max_code_len + 1):
        rate = np.zeros(sample_size)
        use = np.zeros(sample_size)
        msg = read_msg(l)
        for i in range(sample_size):
            pms = PMS(Px, Pe)
            s, v, u = pms.transmit(msg[i], max_channel_use=500)
            if s == msg[i]:
                rate[i] = l / u
                use[i] = u
            print("Progress: {}%".format(
                np.round(
                    100 * ((l - min_code_len) * sample_size + i) /
                    (max_code_len + 1 - min_code_len) / sample_size, 2)))
        # tranx_rate.append(sum(rate)/len(rate))
        tranx_rate[l - 1] = np.mean(rate[np.nonzero(rate)])
        channel_use[l - 1] = np.mean(use[np.nonzero(use)])
    capacity = BSC_capacity(Px)

    # log file
    fn_trx = "pms_len_tranx_rate_{}.txt".format(cmt)
    fn_trx = os.path.join('log', fn_trx)
    with open(fn_trx, 'w') as f:
        for rate in tranx_rate:
            f.write(str(rate) + '\n')

    fn_use = "pms_len_channel_use_{}.txt".format(cmt)
    fn_use = os.path.join('log', fn_use)
    with open(fn_use, 'w') as f:
        for use in channel_use:
            f.write(str(use) + '\n')

    # plot
    x = np.array(range(min_code_len, max_code_len + 1))
    y = tranx_rate
    plt.plot(x, y, label="tranx rate")
    plt.hlines(capacity, 0, max_code_len + 1, colors="coral", label="capacity")

    plt.xlim([0, max_code_len + 1])
    title = "Standard Posterior Matching Scheme"
    plt.title("{}: Pe={}, Px={}, size={}".format(title, Pe, Px, sample_size))
    plt.xlabel("Message length")
    plt.ylabel("Transmission rate")

    plt.legend(loc='lower right')
    plt.savefig(os.path.join("graph", "pms_len_tranx_rate_{}.png".format(cmt)))
    plt.show()
Beispiel #3
0
def test_mpms_once_with_errors_all_corrected(sequence, Px, Pe):
    mpms = MPMS(Px, Pe)
    hamming_msg_len = 4
    s, u, l = mpms.transmit(sequence,
                            max_channel_use=300,
                            err_num=1,
                            msg_len=hamming_msg_len)
    print("Result:\n- number of channel use:{}, len: {} {}".format(
        u, len(sequence), l))
    print("- binary sequence:{}\n- actual sequence:{}".format(s, sequence))
    if s == sequence:
        print("Correct!")
    else:
        print("Wrong!")
    print("Transmission Rate: {}".format(len(sequence) / u / l))
    print("Channel x linear:  {}".format(
        BSC_capacity(Px) * hamming_msg_len / l))
    print("Channel capacity:  {}".format(BSC_capacity(Px)))
Beispiel #4
0
def test_mpms_once_with_errors_not_all_corrected(msg_len, Px, Pe):
    # message and hamming code
    msg = read_msg(msg_len)[233]
    hmsg_len = 10  # hamming message length
    hblk_len = HammingCode.calc_redundant_bits(hmsg_len) + hmsg_len
    print('Hamming({},{})'.format(hblk_len, hmsg_len))

    # modified posterior matching
    mpms = MPMS(Px, Pe)
    s, u, l = mpms.transmit(msg,
                            max_channel_use=500,
                            err_num=None,
                            msg_len=hmsg_len)
    print("Result:\n- number of channel use:{}, len: {} {}".format(
        u, len(msg), l))
    print("- binary sequence:{}\n- actual sequence:{}".format(s, msg))
    if s == msg:
        print("Correct!")
        print("Transmission Rate: {}".format(len(msg) / u / hblk_len))
        print("Channel capacity:  {}".format(BSC_capacity(Px)))
        print("Channel x linear:  {}".format(
            BSC_capacity(Px) * hmsg_len / hblk_len))
    else:
        print("Wrong!")
Beispiel #5
0
def test_pms_once(msg_len, Px, Pe):
    # message
    msg = read_msg(msg_len)[233]

    # posterior matching
    pms = PMS(Px, Pe)
    s, v, u = pms.transmit(msg, max_channel_use=500)  # str, value, use
    print("Result:\n- number of channel use: {}, len: {}\n- result value: {}".
          format(u, len(msg), v))
    print("- binary sequence:{}\n- actual sequence:{}".format(s, msg))
    if s == msg:
        print("Correct!")
        print("Transmission Rate: {}".format(len(msg) / u))
        print("Channel capacity:  {}".format(BSC_capacity(Px)))
    else:
        print("Wrong!")
Beispiel #6
0
def test_cmp_diff_hamming(Px, Pe, cmt):
    min_msg_len = 1
    max_msg_len = 80
    sample_size = 1000

    # read log files
    fn_pms = 'pms_len_tranx_rate.txt'
    fn_52 = 'mpms_len_tranx_rate_(5,2)_{}.txt'.format(cmt)
    fn_63 = 'mpms_len_tranx_rate_(6,3)_{}.txt'.format(cmt)
    fn_74 = 'mpms_len_tranx_rate_(7,4)_{}.txt'.format(cmt)
    fn_1410 = 'mpms_len_tranx_rate_(14,10)_{}.txt'.format(cmt)

    fn_pms = os.path.join('log', fn_pms)
    fn_52 = os.path.join('log', fn_52)
    fn_63 = os.path.join('log', fn_63)
    fn_74 = os.path.join('log', fn_74)
    fn_1410 = os.path.join('log', fn_1410)
    with open(fn_pms, 'r') as f:
        rate_list_pms = f.readlines()
        rate_pms = np.array([np.float32(r.strip()) for r in rate_list_pms])

    with open(fn_52, 'r') as f:
        rate_list_52 = f.readlines()
        rate_52 = np.array([np.float32(r.strip()) for r in rate_list_52])

    with open(fn_63, 'r') as f:
        rate_list_63 = f.readlines()
        rate_63 = np.array([np.float32(r.strip()) for r in rate_list_63])

    with open(fn_74, 'r') as f:
        rate_list_74 = f.readlines()
        rate_74 = np.array([np.float32(r.strip()) for r in rate_list_74])

    with open(fn_1410, 'r') as f:
        rate_list_1410 = f.readlines()
        rate_1410 = np.array([np.float32(r.strip()) for r in rate_list_1410])

    # capacity
    rho1 = hamming_err_prob(Px, 2, 5)
    rho2 = hamming_err_prob(Px, 3, 6)
    rho3 = hamming_err_prob(Px, 4, 7)
    rho4 = hamming_err_prob(Px, 10, 14)
    capacity = BSC_capacity(Px)
    capacity_52 = BSC_Hamming_capacity(5, 2, rho1)
    capacity_63 = BSC_Hamming_capacity(6, 3, rho2)
    capacity_74 = BSC_Hamming_capacity(7, 4, rho3)
    capacity_1410 = BSC_Hamming_capacity(14, 10, rho4)

    # plot
    x = np.array(range(min_msg_len, max_msg_len + 1))
    y1 = rate_pms
    y2 = rate_52
    y3 = rate_63
    y4 = rate_74
    y5 = rate_1410
    c1 = capacity
    c2 = capacity_52
    c3 = capacity_63
    c4 = capacity_74
    c5 = capacity_1410

    plt.plot(x, y1, label="PMS", color='tab:orange')
    plt.plot(x, y2, label="(5,2)", color='black')
    plt.plot(x, y3, label="(6,3)", color='saddlebrown')
    plt.plot(x, y4, label="(7,4)", color='tab:blue')
    plt.plot(x, y5, label="(14,10)", color='tab:green')
    plt.hlines(c1, 0, max_msg_len + 1, colors='red', label="capacity")
    plt.hlines(c2, 0, max_msg_len + 1, colors='gold', label="cap (5,2)")
    plt.hlines(c3, 0, max_msg_len + 1, colors='coral', label="cap (6,3)")
    plt.hlines(c4, 0, max_msg_len + 1, colors='grey', label="cap (7,4)")
    plt.hlines(c5, 0, max_msg_len + 1, colors='blue', label="cap (14,10)")

    plt.xlim([0, max_msg_len + 1])
    plt.ylim([0, c1 * 1.1])
    plt.xlabel("Message length")
    plt.ylabel("Transmission rate")
    plt.title("Comparison: Pe={}, Px={}, size={}, {}".format(
        Pe, Px, sample_size, cmt))
    plt.legend(loc='lower right')
    figname = "cmp_hamming_{}.png".format(cmt)
    plt.savefig(os.path.join("graph", figname))
    plt.show()
Beispiel #7
0
def test_mpms_len_against_tranx_rate_with_not_errors_all_corrected(
        Px, Pe, cmt: str):
    """ Plot message length against transmission rate, write log file
    
    This function will record average transmission rate and channel use for
    each message length. Existent log file will be overwritten. 
    """

    # hamming code
    hmsg_len = 4
    hblk_len = hblk_len = HammingCode.calc_redundant_bits(hmsg_len) + hmsg_len

    # modified posterior mathcing
    min_msg_len = 1
    max_msg_len = 40
    sample_size = 700
    tranx_rate = np.zeros(max_msg_len - min_msg_len + 1)
    channel_use = np.zeros(max_msg_len - min_msg_len + 1)
    for l in range(min_msg_len, max_msg_len + 1):
        rate = np.zeros(sample_size)
        use = np.zeros(sample_size)
        msg = read_msg(l)
        for i in range(sample_size):
            mpms = MPMS(Px, Pe)
            s, u, L = mpms.transmit(msg[i],
                                    max_channel_use=500,
                                    err_num=None,
                                    msg_len=hmsg_len)
            if s == msg[i]:
                rate[i] = l / u / hblk_len
                use[i] = u
            print("Progress: {}%".format(
                np.round(
                    100 * ((l - min_msg_len) * sample_size + i) /
                    (max_msg_len + 1 - min_msg_len) / sample_size, 2)))
        # tranx_rate.append(sum(rate)/len(rate))
        tranx_rate[l - 1] = np.mean(rate[np.nonzero(rate)])
        channel_use[l - 1] = np.mean(use[np.nonzero(use)])

    # log file
    fn_trx = "mpms_len_tranx_rate_({},{})_{}.txt".format(
        hblk_len, hmsg_len, cmt)
    fn_trx = os.path.join('log', fn_trx)
    with open(fn_trx, 'w') as f:
        for rate in tranx_rate:
            f.write(str(rate) + '\n')

    fn_use = "mpms_len_channel_use_({},{})_{}.txt".format(
        hblk_len, hmsg_len, cmt)
    fn_use = os.path.join('log', fn_use)
    with open(fn_use, 'w') as f:
        for use in channel_use:
            f.write(str(use) + '\n')

    # plot
    x = np.array(range(min_msg_len, max_msg_len + 1))
    y1 = tranx_rate
    c1 = BSC_capacity(Px)
    c2 = BSC_Hamming_capacity(hblk_len, hmsg_len,
                              hamming_err_prob(Px, hmsg_len, hblk_len))
    plt.plot(x, y1, label="tranx rate")
    plt.hlines(c1, 0, max_msg_len + 1, colors="coral", label="BSC capacity")
    plt.hlines(c2, 0, max_msg_len + 1, color='lime', label="Cap with Hamming")

    plt.xlim([0, max_msg_len + 1])
    title = 'Modified Posterior Matching Scheme: Pe={}, Px={}, '.format(Pe, Px)
    plt.title("{}size={}, hamming({},{})".format(title, sample_size, hblk_len,
                                                 hmsg_len))
    plt.xlabel("Message length")
    plt.ylabel("Transmission rate")

    plt.legend(loc='lower right')
    figname = "mpms_len_tranx_rate_({},{})_{}.png".format(
        hblk_len, hmsg_len, cmt)
    plt.savefig(os.path.join("graph", figname))
    plt.show()
Beispiel #8
0
def test_mismatched_Px(Px, Pe, msgL=4):

    min_msg_len = 1
    max_msg_len = 39
    sample_size = "700/1000"

    # hamming code
    hmsg_len = msgL
    hblk_len = HammingCode.calc_redundant_bits(hmsg_len) + hmsg_len
    hrate = "{}/{}".format(hmsg_len, hblk_len)
    name = 'Hamming({},{})'.format(hblk_len, hmsg_len)

    # read log files
    fn_pms = 'pms_len_tranx_rate.txt'
    fn_HEP = 'mpms_len_tranx_rate_({},{})_Ps=HEP.txt'.format(
        hblk_len, hmsg_len)
    fn_mm = 'mpms_len_tranx_rate_({},{})_mismatched_Px.txt'.format(
        hblk_len, hmsg_len)
    fn_pms = os.path.join('log', fn_pms)
    fn_HEP = os.path.join('log', fn_HEP)
    fn_mm = os.path.join('log', fn_mm)

    with open(fn_pms, 'r') as f:
        rate_list_pms = f.readlines()
        rate_pms = np.array([np.float32(r.strip()) for r in rate_list_pms])

    with open(fn_HEP, 'r') as f:
        rate_list_HEP = f.readlines()
        rate_HEP = np.array([np.float32(r.strip()) for r in rate_list_HEP])

    with open(fn_mm, 'r') as f:
        rate_list_mm = f.readlines()
        rate_mm = np.array([np.float32(r.strip()) for r in rate_list_mm])

    # capacity
    capacity = BSC_capacity(Px)
    rho1 = hamming_err_prob(Px, hmsg_len, hblk_len)
    capacity_with_HEP = BSC_Hamming_capacity(hblk_len, hmsg_len, rho1)

    # data to be plotted
    x = np.array(range(min_msg_len, max_msg_len + 1))
    y1 = rate_pms[min_msg_len:max_msg_len + 1]
    y2 = rate_HEP[min_msg_len:max_msg_len + 1]
    y3 = rate_mm[min_msg_len:max_msg_len + 1]
    c1 = capacity
    c2 = capacity_with_HEP

    # plot
    figname = "cmp_len_tranx_rate_{}_with_mismatched_Px.png".format(name)
    plt.plot(x, y1, label="PMS", color='tab:orange')
    plt.plot(x, y2, label=name, color='tab:blue')
    plt.plot(x, y3, label="mismatched", color='tab:green')
    plt.hlines(c1, 0, max_msg_len + 1, colors='red', label="capacity")
    plt.hlines(c2, 0, max_msg_len + 1, colors='m', label="cap of HEP")

    plt.xlim([0, max_msg_len + 1])
    plt.ylim([0, c1 * 1.1])
    plt.xlabel("Message length")
    plt.ylabel("Transmission rate")
    plt.legend(loc='lower right')
    plt.title("Comparison: Pe={},Px={},size={},{}".format(
        Pe, Px, sample_size, name))
    plt.savefig(os.path.join("graph", figname))
    plt.show()
Beispiel #9
0
def test_cmp_hamming_7_4_diff_Px(Pe):
    min_msg_len = 1
    max_msg_len = 34
    sample_size = 700

    # read log files
    fn_pms_1 = 'pms_len_tranx_rate_Px=0.1.txt'
    fn_pms_2 = 'pms_len_tranx_rate.txt'
    fn_pms_3 = 'pms_len_tranx_rate_Px=0.3.txt'
    fn_HEP_1 = 'mpms_len_tranx_rate_(7,4)_Px=0.1.txt'
    fn_HEP_2 = 'mpms_len_tranx_rate_(7,4)_Ps=HEP.txt'
    fn_HEP_3 = 'mpms_len_tranx_rate_(7,4)_Px=0.3.txt'
    fn_pms_1 = os.path.join('log', fn_pms_1)
    fn_pms_2 = os.path.join('log', fn_pms_2)
    fn_pms_3 = os.path.join('log', fn_pms_3)
    fn_HEP_1 = os.path.join('log', fn_HEP_1)
    fn_HEP_2 = os.path.join('log', fn_HEP_2)
    fn_HEP_3 = os.path.join('log', fn_HEP_3)

    with open(fn_pms_1, 'r') as f:
        rate_list_pms_1 = f.readlines()
        rate_pms_1 = np.array([np.float32(r.strip()) for r in rate_list_pms_1])

    with open(fn_pms_2, 'r') as f:
        rate_list_pms_2 = f.readlines()
        rate_pms_2 = np.array([np.float32(r.strip()) for r in rate_list_pms_2])

    with open(fn_pms_3, 'r') as f:
        rate_list_pms_3 = f.readlines()
        rate_pms_3 = np.array([np.float32(r.strip()) for r in rate_list_pms_3])

    with open(fn_HEP_1, 'r') as f:
        rate_list_HEP_1 = f.readlines()
        rate_HEP_1 = np.array([np.float32(r.strip()) for r in rate_list_HEP_1])

    with open(fn_HEP_2, 'r') as f:
        rate_list_HEP_2 = f.readlines()
        rate_HEP_2 = np.array([np.float32(r.strip()) for r in rate_list_HEP_2])

    with open(fn_HEP_3, 'r') as f:
        rate_list_HEP_3 = f.readlines()
        rate_HEP_3 = np.array([np.float32(r.strip()) for r in rate_list_HEP_3])

    # capacity
    capacity_1 = BSC_capacity(0.1)
    capacity_2 = BSC_capacity(0.2)
    capacity_3 = BSC_capacity(0.3)
    rho1 = hamming_err_prob(0.1, 4, 7)
    rho2 = hamming_err_prob(0.2, 4, 7)
    rho3 = hamming_err_prob(0.3, 4, 7)
    capacity_with_HEP_1 = BSC_Hamming_capacity(7, 4, rho1)
    capacity_with_HEP_2 = BSC_Hamming_capacity(7, 4, rho2)
    capacity_with_HEP_3 = BSC_Hamming_capacity(7, 4, rho3)

    # data to be plotted
    x = np.array(range(min_msg_len, max_msg_len + 1))
    y1 = rate_pms_1[min_msg_len:max_msg_len + 1]
    y2 = rate_pms_2[min_msg_len:max_msg_len + 1]
    y3 = rate_pms_3[min_msg_len:max_msg_len + 1]
    y4 = rate_HEP_1[min_msg_len:max_msg_len + 1]
    y5 = rate_HEP_2[min_msg_len:max_msg_len + 1]
    y6 = rate_HEP_3[min_msg_len:max_msg_len + 1]
    c1 = capacity_1
    c2 = capacity_2
    c3 = capacity_3
    c4 = capacity_with_HEP_1
    c5 = capacity_with_HEP_2
    c6 = capacity_with_HEP_3

    # plot
    figname = "cmp_len_tranx_rate_diff_Px.png"
    fig, (ax1, ax2, ax3) = plt.subplots(1, 3)
    ax1.plot(x, y1, label="PMS .1", color='tab:blue')
    ax1.plot(x, y4, label="MPMS .1", color='tab:orange')
    ax1.hlines(c1, 0, max_msg_len + 1, colors='red', label="cap PMS .1")
    ax1.set_xlim([0, max_msg_len + 1])
    ax1.set_ylim([0, c1 * 1.1])
    ax1.set_xlabel("Message length")
    ax1.legend(loc='lower right')
    ax1.spines['bottom'].set_linewidth(0.5)

    ax2.plot(x, y2, label="PMS .2", color='tab:blue')
    ax2.plot(x, y5, label="MPMS .2", color='tab:orange')
    ax2.hlines(c2, 0, max_msg_len + 1, colors='red', label="cap PMS .2")
    ax2.set_xlim([0, max_msg_len + 1])
    ax2.set_ylim([0, c1 * 1.1])
    ax2.set_xlabel("Message length")
    ax2.legend(loc='upper right')

    ax3.plot(x, y3, label="PMS .3", color='tab:blue')
    ax3.plot(x, y6, label="MPMS .3", color='tab:orange')
    ax3.hlines(c3, 0, max_msg_len + 1, colors='red', label="cap PMS .3")
    ax3.set_xlim([0, max_msg_len + 1])
    ax3.set_ylim([0, c1 * 1.1])
    ax3.set_xlabel("Message length")
    ax3.legend(loc='upper right')

    # plt.hlines(c4, 0, max_msg_len+1, colors='m', label="cap MPMS .1")
    # plt.hlines(c5, 0, max_msg_len+1, colors='m', label="cap MPMS .2")
    # plt.hlines(c6, 0, max_msg_len+1, colors='m', label="cap MPMS .3")

    fig.suptitle("Comparison: Pe={}, size={}, diff Px".format(
        Pe, Px, sample_size))
    plt.savefig(os.path.join("graph", figname))
    plt.show()
Beispiel #10
0
def test_cmp_code_len_against_tranx_rate(Px, Pe, msgL=4, est=False):
    """ Read logs, plot message length against transmission rate and capacity
    
    This function will read log files recording average transmission rate and 
    channel use for each message length and compare them with channel complexity. 
    """

    min_msg_len = 1
    max_msg_len = 80
    sample_size = 1000

    # hamming code
    hmsg_len = msgL
    hblk_len = HammingCode.calc_redundant_bits(hmsg_len) + hmsg_len
    hrate = "{}/{}".format(hmsg_len, hblk_len)
    name = 'Hamming({},{})'.format(hblk_len, hmsg_len)

    # read log files
    fn_pms = 'pms_len_tranx_rate.txt'
    fn_HEP = 'mpms_len_tranx_rate_({},{})_Ps=HEP.txt'.format(
        hblk_len, hmsg_len)
    fn_pms = os.path.join('log', fn_pms)
    fn_HEP = os.path.join('log', fn_HEP)

    with open(fn_pms, 'r') as f:
        rate_list_pms = f.readlines()
        rate_pms = np.array([np.float32(r.strip()) for r in rate_list_pms])

    with open(fn_HEP, 'r') as f:
        rate_list_HEP = f.readlines()
        rate_HEP = np.array([np.float32(r.strip()) for r in rate_list_HEP])

    if est:  # estimate scaled probability
        fn_Px = 'mpms_len_tranx_rate_({},{})_Ps=Px.txt'.format(
            hblk_len, hmsg_len)
        fn_LOEP = 'mpms_len_tranx_rate_({},{})_Ps=LOEP.txt'.format(
            hblk_len, hmsg_len)
        fn_Px = os.path.join('log', fn_Px)
        fn_LOEP = os.path.join('log', fn_LOEP)

        with open(fn_Px, 'r') as f:
            rate_list_Px = f.readlines()
            rate_Px = np.array([np.float32(r.strip()) for r in rate_list_Px])

        with open(fn_LOEP, 'r') as f:
            rate_list_LOEP = f.readlines()
            rate_LOEP = np.array(
                [np.float32(r.strip()) for r in rate_list_LOEP])

    # capacity
    capacity = BSC_capacity(Px)
    rho1 = hamming_err_prob(Px, hmsg_len, hblk_len)
    capacity_with_HEP = BSC_Hamming_capacity(hblk_len, hmsg_len, rho1)
    if est:
        rho2 = hamming_LOEP(Px, hblk_len)
        capacity_with_LOEP = BSC_Hamming_capacity(hblk_len, hmsg_len, rho2)

    # data to be plotted
    x = np.array(range(min_msg_len, max_msg_len + 1))
    y1 = rate_pms
    y2 = rate_HEP
    y3 = rate_pms * hmsg_len / hblk_len
    c1 = capacity
    c2 = capacity_with_HEP
    c3 = capacity * hmsg_len / hblk_len
    if est:
        y4 = rate_Px
        y5 = rate_LOEP
        c5 = capacity_with_LOEP

    # plot
    figname = "cmp_len_tranx_rate_{}.png".format(name)
    plt.plot(x, y1, label="PMS", color='tab:orange')
    plt.plot(x, y2, label=name, color='tab:blue')
    plt.plot(x, y3, label="PMS x {}".format(hrate), color='tab:green')
    plt.hlines(c1, 0, max_msg_len + 1, colors='red', label="capacity")
    plt.hlines(c2, 0, max_msg_len + 1, colors='m', label="cap of HEP")
    if est:
        plt.plot(x, y4, label="Crossover", color='saddlebrown')
        plt.plot(x, y5, label="LOEP", color='black')
        # plt.hlines(c5, 0, max_msg_len+1, colors='cyan', label="cap of LOEP")
        figname = "cmp_len_tranx_rate_{}_EST.png".format(name)

    plt.xlim([0, max_msg_len + 1])
    plt.ylim([0, c1 * 1.1])
    plt.xlabel("Message length")
    plt.ylabel("Transmission rate")
    plt.legend(loc='lower right')
    plt.title("Comparison: Pe={},Px={},size={},{}".format(
        Pe, Px, sample_size, name))
    plt.savefig(os.path.join("graph", figname))
    plt.show()