当前位置:网站首页>MMR rearrangement (similarity is calculated by editing distance and repeatability)
MMR rearrangement (similarity is calculated by editing distance and repeatability)
2022-06-28 07:22:00 【Wang Xiaoer riding a bicycle】
def leven_shtein_score(self,query1,query2):# Relative edit distance ( The smaller the relative editing distance , The higher the similarity )
bias=0.0001
res=(Levenshtein.distance(query1,query2))/(max(len(query1),len(query2))+bias)
return res
def repeat_score(self,query1,query2):#query Repeatability between
bias=0.0001
res = len(list(filter(set(query2).__contains__, query1)))/(len(query2)+bias)
return res
def similar_score(self,querys):#query Calculation of similarity between
similarityMatrix=[[0 for i in range(len(querys))] for j in range(len(querys))]
for i in range(len(querys)):
for j in range(len(querys)):
if i==j:
similarityMatrix[i][j]=1
else:
similarityMatrix[i][j]=max((self.repeat_score(querys[i],querys[j])-self.leven_shtein_score(querys[i],querys[j])),0)
return similarityMatrix
def MMR(self,recScoreDict, similarityMatrix,lambdaConstant=0.5, topN=20):#MMR rearrangement ( Correlation scores of recommenders and similarity matrix between recommenders )
s, r = [], [i for i in range(len(recScoreDict))]
while len(r) > 0:
score = 0
selectOne = None
for i in r:
firstPart = recScoreDict[i]
secondPart = 0
for j in s:
sim2 = float(similarityMatrix[i][j])
if sim2 > secondPart:
secondPart = sim2
equationScore = lambdaConstant * firstPart - (1 - lambdaConstant) * secondPart
if equationScore > score:
score = equationScore
selectOne = i
if selectOne == None:
selectOne = i
r.remove(selectOne)
s.append(selectOne)
return (s, s[:topN])[topN > len(s)]
边栏推荐
- Drawing animated bubble chart with R language
- kubernetes删除pod的流程的源码简析
- Devtools implementation principle and performance analysis practice
- 7-1 懂的都懂
- Practice of traffic recording and playback in vivo
- MySQL installation steps - Linux configuration file JDK installation (II)
- Recommend several 0 code, free, learning and using visualization tools
- 面经---测试工程师web端自动化---大厂面试题
- ABAP 技能树
- 卸载重装最新版mysql数据库亲测有效
猜你喜欢
What should I do if the version is incompatible with the jar package conflict?
在idea中,get和set方法爆红可能是没有安装Lombok插件
全方位透析真实企业软件测试流程
Path alias specified in vite2.9
Comprehensive analysis of real enterprise software testing process
goland IDE和delve调试位于kubernetes集群中的go程序
Modifying MySQL user name root under Linux
BACnet/IP網關如何采集樓宇集中控制系統數據
Design and practice of vivo sensitive word matching system
编译原理期末复习
随机推荐
东方财富上开户是安全的吗
Is it safe to open an account on Dongfang fortune
7-1 懂的都懂
Jinshan cloud team shared | 5000 words to understand how Presto matches with alluxio
Hungry for a long time, the brain will enter the "power saving mode"! Your senses are weakened and you can't see clearly
同花顺网上开户安全吗
Libuv框架echo-server.c源码详解(TCP部分)
Will Internet talents be scarce in the future? Which technology directions are popular?
声网 VQA:将实时互动中未知的视频画质用户主观体验变可知
强化学习——格子世界
Recommend several 0 code, free, learning and using visualization tools
A gadget can write crawlers faster
Design and practice of vivo sensitive word matching system
Construction and exploration of vivo database and storage platform
什么是EC鼓风机(ec blower fan)?
Vivo browser rapid development platform practice - Overview
In idea, the get and set methods may be popular because the Lombok plug-in is not installed
Mysql8.0 and mysql5.0 accessing JDBC connections
C语言教程大全
Pytorch RNN learning notes