gpt4 book ai didi

compression - Sequitur算法的Python实现?

转载 作者:行者123 更新时间:2023-12-02 01:33:54 25 4
gpt4 key购买 nike

我需要将 Sequitur 算法用于生物信息学项目,但到目前为止我还没有找到该算法的任何 Python 实现。这是我到目前为止所得到的:

    def new_rule(sequence,rules,x,y,z):
y = list(y)
if max(y) > 1:
ind = y.index(max(y))

locations = np.zeros(max(y))

counter = 0
for i, j in enumerate(z):
if j == x[ind]:
locations[counter] = i
counter+=1

new_rule = 'A'+str(len(rules)+1)
rules.append([new_rule,x[ind]])

return sequence.replace(x[ind],new_rule), rules

def word_count(sequence):
return len(sequence)-sequence.count(' ')

def recursive_sequitur(sequence,rules):
count_down = word_count(sequence)-1

x,y,z = n_grams(sequence,count_down)

while count_down>1:
if len(y) > 1 and max(y) > 1:
sequence, rules = new_rule(sequence,rules,x,y,z)
x,y,z = n_grams(sequence,count_down)

else:
count_down-=1
x,y,z = n_grams(sequence,count_down)

return sequence, rules

最佳答案

你见过Parallel Sequitur吗?对于 Python?

We implemented serial and parallel versions of the Sequitur compression algorithm. The Sequitur algorithm uses hierarchical structure and sequences of discrete symbols to compress files by exploiting repetative structures found in strings.

concat_parallel.py :Sequitur 算法的简单并行实现。在主进程按顺序合并所有结果之前,文本在运行串行算法版本的工作人员之间拆分。

关于compression - Sequitur算法的Python实现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32402789/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com