예제 #1
0
            for j, yj in enumerate(y):
                D[i + 1][j + 1] = D[i][j + 1]

                if xi == yj:
                    ly = j
                if ly != -1:
                    D[i + 1][j + 1] = D[i][j + 1] + D[i][ly]
                    if L_x[i] != -1:
                        D[i + 1][j + 1] -= D[L_x[i]][ly]

        return D[len(x)][len(y)]


if __name__ == "__main__":

    x = [Symbol.SymbolItem(i) for i in ['a', 'b', 'a', 'c']]
    y = [Symbol.SymbolItem(i) for i in ['b', 'a', 'c', 'b']]

    char_weights = {
        Symbol.SymbolItem('a'): np.sqrt(2),
        Symbol.SymbolItem('c'): np.sqrt(3)
    }
    k = VersatileKernel(lmb=1, char_weights=char_weights)
    print(k.kernel(x, y))

    char_weights = {
        Symbol.SymbolItem('a'): np.sqrt(1),
        Symbol.SymbolItem('c'): np.sqrt(1)
    }

    x = [Symbol.SymbolItem(i) for i in "abacbaca"]
예제 #2
0
    def print_results(X, con_results):
        print("================================================")
        print("********************************")
        print("The Set X of the Ordering Sequences:")
        for x in X:
            print(x)
        print("********************************")
        print("k(X)= {}   --The concordance of X".format(con_results[0]))
        print("l(x)= {}   --The length of the longest common subsequences".
              format(con_results[1]))
        print("All LCSs: {} ".format(con_results[2]))
        print("The  Smallest Covering Set C(X): {} ".format(con_results[3]))
        print("================================================\n\n")

    X = []
    X.append([Symbol.SymbolItem(i) for i in ['a', 'b', 'c', 'd', 'e', 'f']])
    X.append([Symbol.SymbolItem(i) for i in ['a', 'c', 'f', 'b', 'd', 'e']])
    X.append([Symbol.SymbolItem(i) for i in ['a', 'b', 'd', 'c', 'f', 'e']])
    con = ConcordanceAndSmallestCoveringSet()
    print_results(X, con.calculate_concordance(X))

    X = []
    X.append([Symbol.SymbolItem(i) for i in ['a', 'b', 'c', 'd', 'f', 'e']])
    X.append([Symbol.SymbolItem(i) for i in ['a', 'd', 'b', 'c', 'f', 'e']])
    X.append([Symbol.SymbolItem(i) for i in ['a', 'd', 'f', 'b', 'e', 'c']])
    con = ConcordanceAndSmallestCoveringSet()
    print_results(X, con.calculate_concordance(X))

    X = []
    X.append([Symbol.SymbolItem(i) for i in ['f', 'a', 'b', 'c', 'd', 'e']])
    X.append([Symbol.SymbolItem(i) for i in ['e', 'a', 'f', 'd', 'b', 'c']])