ssk_by_Mona.py 文件源码

python
阅读 33 收藏 0 点赞 0 评论 0

项目:MachineLearningProject 作者: ymynem 项目源码 文件源码
def subsequence_kernel_primed_lru_wrapped(s, t):
    @lru_cache(maxsize=None)
    def subsequence_kernel_primed(s_counter, jtot, l, i):  # where (i = 1, … , n-1)
        """
        In order to deal with non-contiguous substrings, it is necessary to
        introduce a decay factor ? ? (0, 1) that can be used to weight the presence of a certain feature in a text
        :param s: string 1
        :param t: string 2
        :param l: lambda represents the weight?
        :param i: length of subsequence
        :return:
        """
        if i == 0:
            return 1
        elif min(s_counter, jtot) < i:  #
            return 0
        else:
            s_counter_minus_one = s_counter - 1
            x = s[s_counter_minus_one]  # last character. sx means the hole string, when they write only s they mean exclude last char
            the_sum = 0
            i_minus_one = i -1
            for j in range(jtot):
                if x == t[j]:
                    the_sum += subsequence_kernel_primed(s_counter_minus_one, j, l, i_minus_one) * l ** (jtot - j + 2)
        res = l * subsequence_kernel_primed(s_counter_minus_one, jtot, l, i) + the_sum
        return res

    return subsequence_kernel_primed
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号