import math


def cal_similarity(s, m, t):
    """
    calculate similarity between current session and neighbourhood session
    :param s: current session
    :param m: candidate neighbourhood session
    :param t: timestamp
    :return: similarity
    """
    s = set(s[:t + 1])
    m = set(m)
    return len(s & m) / math.sqrt(len(s) * len(m))