Пример #1
0
 def decode(file,
            error_correction=nocode,
            null_is_terminator=False,
            mode_1_bmp=False,
            number_of_chunks=STATIC_NUM_CHUNKS,
            use_header_chunk=False,
            id_len_format=ID_LEN_FORMAT,
            number_of_chunks_len_format=NUMBER_OF_CHUNKS_LEN_FORMAT,
            packet_len_format=PACKET_LEN_FORMAT,
            crc_len_format=CRC_LEN_FORMAT,
            read_all=READ_ALL_BEFORE_DECODER,
            distribution_cfg_str=""):
     dist = ErlichZielinskiRobustSolitonDistribution(number_of_chunks,
                                                     seed=2)
     if distribution_cfg_str != "":
         # parse distribution_cfg_str and create distribution with the defined settings...
         splt = distribution_cfg_str.split("_")
         mode = splt[1]
         if mode == "ErlichZielinskiRobustSoliton":
             k = int(splt[2].split("=")[1])
             delta = float(splt[3].split("=")[1])
             c = float(splt[4].split("=")[1])
             dist = ErlichZielinskiRobustSolitonDistribution(k,
                                                             delta,
                                                             c,
                                                             seed=2)
         elif mode == "RobustSoliton":
             k = int(splt[2].split("=")[1])
             delta = float(splt[3].split("=")[1])
             dist = RobustSolitonDistribution(number_of_chunks,
                                              k,
                                              delta,
                                              seed=2)
         elif mode == "IdealSoliton":
             dist = IdealSolitonDistribution(number_of_chunks, seed=2)
     """try:
         decoder = LTBPDecoder(file, error_correction=error_correction, use_headerchunk=HEADER_CHUNK,
                                   static_number_of_chunks=STATIC_NUM_CHUNKS, implicit_mode=IMPLICIT_MODE, dist=dist)
         print("[1/2] Approximation Decode")
         _internal(decoder)
         if not decoder.is_decoded():
             print("[2/2] Approximation Decode")
             _internal(decoder)
         decoder.saveDecodedFile(null_is_terminator=NULL_IS_TERMINATOR)
     except Exception as e:"""
     print("[X/2] Falling back to Gauss-Mode")
     print("Falling back to Gauss-Mode")
     decoder = LTDecoder(file,
                         error_correction=error_correction,
                         use_headerchunk=use_header_chunk,
                         static_number_of_chunks=number_of_chunks,
                         implicit_mode=IMPLICIT_MODE,
                         dist=dist)
     decoder.read_all_before_decode = read_all
     decoder.decode(number_of_chunks_len_format=number_of_chunks_len_format,
                    seed_len_format=id_len_format,
                    degree_len_format="H")
     decoder.solve()
     decoder.saveDecodedFile(null_is_terminator=null_is_terminator,
                             print_to_output=PRINT_TO_OUTPUT)
Пример #2
0
def main(file,
         number_of_chunks: int = 0,
         chunk_size: int = 0,
         error_correction: typing.Callable = nocode,
         as_dna: bool = False,
         insert_header: bool = False,
         save_number_of_chunks=False):
    if chunk_size != 0:
        number_of_chunks = Encoder.get_number_of_chunks_for_file_with_chunk_size(
            file, chunk_size)
    if as_dna:
        rules = FastDNARules()
    else:
        rules = None
    dist = ErlichZielinskiRobustSolitonDistribution(number_of_chunks, seed=2)
    encoder = LTEncoder(file,
                        number_of_chunks,
                        dist,
                        insert_header=insert_header,
                        rules=rules,
                        error_correction=error_correction,
                        number_of_chunks_len_format="H",
                        id_len_format="I",
                        used_packets_len_format="H",
                        save_number_of_chunks_in_packet=save_number_of_chunks,
                        implicit_mode=False)
    encoder.encode_to_packets()
    print("Number of Chunks=%s" % encoder.number_of_chunks)
    encoder.save_packets(split_to_multiple_files=True, save_as_dna=as_dna)
Пример #3
0
def main(file: str, number_of_chunks: int, error_correction: typing.Callable, insertheader: bool):
    dist = ErlichZielinskiRobustSolitonDistribution(number_of_chunks, seed=2)

    decoder = LTDecoder(file, error_correction=error_correction, use_headerchunk=insertheader,
                        static_number_of_chunks=number_of_chunks, implicit_mode=False, dist=dist)
    decoder.decode(number_of_chunks_len_format="H", seed_len_format="I", degree_len_format="H")
    decoder.saveDecodedFile(null_is_terminator=False)
Пример #4
0
def get_err_dist(_method, _number_of_chunks, _repair_symbols):
    if _method == 'RU10':
        dist = RaptorDistribution(_number_of_chunks)
    elif _method == 'LT':
        dist = ErlichZielinskiRobustSolitonDistribution(_number_of_chunks,
                                                        seed=2)
    elif _method == 'Online':
        dist = OnlineDistribution(ONLINE_EPS)
    else:
        raise NotImplementedError("Choose: RU10, LT or Online")
    return dist, lambda x: reed_solomon_encode(x, _repair_symbols)
Пример #5
0
def test_erlich_zielinski_dnarules():
    dir_path = os.getcwd()
    try:
        os.remove(dir_path + "/DEC_" + out_dir2)
    except:
        print("Not deleting, File did not exists")
    shutil.copyfile(dir_path + "/" + cmp_file2, dir_path + "/" + file2)
    chunksize = 75
    number_of_chunks = Encoder.get_number_of_chunks_for_file_with_chunk_size(
        file2, chunksize)
    pseudo_decoder = LTDecoder.pseudo_decoder(number_of_chunks)
    dist = ErlichZielinskiRobustSolitonDistribution(k=number_of_chunks,
                                                    delta=0.2,
                                                    seed=2)
    rules = DNARules_ErlichZielinski()
    encoder = LTEncoder(file2,
                        number_of_chunks,
                        dist,
                        error_correction=reed_solomon_encode,
                        chunk_size=chunksize,
                        rules=rules,
                        insert_header=False,
                        number_of_chunks_len_format="H",
                        id_len_format="H",
                        used_packets_len_format="H",
                        pseudo_decoder=pseudo_decoder,
                        implicit_mode=True,
                        save_number_of_chunks_in_packet=False)
    encoder.encode_to_packets()
    encoder.save_packets(split_to_multiple_files=True, save_as_dna=True)
    assert pseudo_decoder.is_decoded() and pseudo_decoder.getSolvedCount(
    ) == encoder.number_of_chunks
    assert os.path.exists(out_dir2)
    decoder = LTDecoder(out_dir2,
                        use_headerchunk=False,
                        dist=dist,
                        implicit_mode=True,
                        static_number_of_chunks=encoder.number_of_chunks,
                        error_correction=reed_solomon_decode)
    decoder.decodeFolder(number_of_chunks_len_format="H",
                         seed_len_format="H",
                         degree_len_format="H")
    assert decoder.is_decoded() and decoder.getSolvedCount(
    ) == encoder.number_of_chunks
    decoder.saveDecodedFile(print_to_output=False, null_is_terminator=True)
    out_file2 = "DEC_LT_" + file2
    assert os.path.exists(out_file2) and filecmp.cmp(out_file2, cmp_file2)
    os.remove(out_file2)
Пример #6
0
def test_lt(args):
    dist = ErlichZielinskiRobustSolitonDistribution(args[2], seed=2)
    decoder = LTDecoder(args[0],
                        error_correction=nocode,
                        use_headerchunk=args[1],
                        static_number_of_chunks=args[2],
                        implicit_mode=False,
                        dist=dist)
    decoder.decode(number_of_chunks_len_format="H",
                   seed_len_format="I",
                   degree_len_format="H")
    decoder.saveDecodedFile(null_is_terminator=False, print_to_output=False)
    if not args[1]:
        out_file = "DEC_LT_logo.jpg"
    else:
        out_file = file_lst[1]
    remove_nullbytes(out_file)
    assert os.path.exists(out_file) and filecmp.cmp(file, out_file)
Пример #7
0
def erlich_zielinski_robust_soliton_dist():
    for a in ["log", ""]:
        dist = ErlichZielinskiRobustSolitonDistribution(k=100,
                                                        c=0.1,
                                                        delta=0.05,
                                                        seed=0)
        print(dist.pre_comp_dist)
        if a == "log":
            plt.semilogy([0.0] + dist.pre_comp_dist, label="log ErlichZlinski")
        else:
            plt.plot([0.0] + dist.pre_comp_dist, label="ErlichZlinski")
        """
        dist = OnlineDistribution(eps=0.03, seed=0)
        print("eps = 0.03")
        print(dist.pre_comp_dist[:30])
        if a == "log":
            plt.semilogy([0.0] + dist.pre_comp_dist[:30], label="$\epsilon$ = 0.03")
        else:
            plt.plot([0.0] + dist.pre_comp_dist[:30], label="$\epsilon$ = 0.03")

        dist = OnlineDistribution(eps=0.06, seed=0)
        print("eps = 0.06")
        print(dist.pre_comp_dist[:30])
        if a == "log":
            plt.semilogy([0.0] + dist.pre_comp_dist[:30], label="$\epsilon$ = 0.06")
        else:
            plt.plot([0.0] + dist.pre_comp_dist[:30], label="$\epsilon$ = 0.06")
    """
        plt.ylabel("Probability")
        plt.xlabel("Degree")
        plt.xticks(np.arange(0, 101, step=5))
        manager = plt.get_current_fig_manager()
        # manager.resize(*manager.window.maxsize())
        plt.grid(True)
        plt.tight_layout()
        plt.legend()
        plt.show(block=True)

        plt.close()
Пример #8
0
def test_suite(as_dna, decoder_instance, distribution, use_header,
               implicit_mode):
    dir_path = os.getcwd()
    try:
        os.remove(dir_path + "/" + file)
    except:
        print("Not deleting, File did not exists")
    shutil.copyfile(dir_path + "/" + cmp_file, dir_path + "/" + file)
    chunksize = 200
    number_of_chunks = Encoder.get_number_of_chunks_for_file_with_chunk_size(
        file, chunksize)
    pseudo_decoder = decoder_instance.pseudo_decoder(number_of_chunks)
    if distribution == "robust":
        dist = RobustSolitonDistribution(S=number_of_chunks, delta=0.2, seed=2)
    elif distribution == "ideal":
        dist = IdealSolitonDistribution(S=number_of_chunks, seed=2)
    else:
        dist = ErlichZielinskiRobustSolitonDistribution(k=number_of_chunks,
                                                        delta=0.2,
                                                        seed=2)
    rules = FastDNARules() if as_dna else None
    encoder = LTEncoder(file,
                        number_of_chunks,
                        dist,
                        chunk_size=chunksize,
                        pseudo_decoder=pseudo_decoder,
                        rules=rules,
                        insert_header=use_header,
                        number_of_chunks_len_format="H",
                        id_len_format="H",
                        used_packets_len_format="H",
                        implicit_mode=implicit_mode)
    encoder.encode_to_packets()
    encoder.save_packets(split_to_multiple_files=True, save_as_dna=as_dna)
    assert pseudo_decoder.is_decoded() and pseudo_decoder.getSolvedCount(
    ) == encoder.number_of_chunks
    assert os.path.exists(out_dir)
    decoder = decoder_instance(out_dir,
                               use_headerchunk=use_header,
                               dist=dist,
                               implicit_mode=implicit_mode)
    decoder.decodeFolder(number_of_chunks_len_format="H",
                         seed_len_format="H",
                         degree_len_format="H")
    assert decoder.is_decoded() and decoder.getSolvedCount(
    ) == encoder.number_of_chunks
    os.remove(file)
    decoder.saveDecodedFile(print_to_output=False)
    if not use_header:
        out_file = "DEC_LT_" + file
    else:
        out_file = file
    assert os.path.exists(out_file) and filecmp.cmp(out_file, cmp_file)
    if decoder_instance == LTBPDecoder:
        # since ApproxDecoder defines an upper bound Gauss-Decoder MUST be able to decode!
        decoder = LTDecoder(out_dir,
                            use_headerchunk=use_header,
                            dist=dist,
                            implicit_mode=implicit_mode)
        decoder.decodeFolder(number_of_chunks_len_format="H",
                             seed_len_format="H",
                             degree_len_format="H")
        assert (decoder.is_decoded()
                and decoder.getSolvedCount() == encoder.number_of_chunks)
        os.remove(out_file)
        decoder.saveDecodedFile(print_to_output=False)
        assert os.path.exists(out_file) and filecmp.cmp(out_file, cmp_file)
    shutil.rmtree(out_dir)