当前位置:网站首页>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)]
边栏推荐
- C language tutorial
- Is it safe to open a stock trading account on your mobile phone?
- 以动态规划的方式求解最长回文子串
- QT -- 通讯协议
- Yesterday, I went to a large factory for an interview and asked me to do four arithmetic operations. Fortunately, I am smart enough
- Solving the longest palindrome substring by dynamic programming
- [rust daily] published on rust 1.43.0 on April 23, 2020
- SQL statement optimization steps (1)
- Jinshan cloud team shared | 5000 words to understand how Presto matches with alluxio
- 剑指offer II 091.粉刷房子
猜你喜欢

BACnet/IP網關如何采集樓宇集中控制系統數據

Recommend 10 popular jupyter notebook plug-ins to make you fly efficiently

BACnet/IP网关如何采集楼宇集中控制系统数据

Voice network VQA: make the user's subjective experience of unknown video quality in real-time interaction known

kubernetes部署thanos ruler的发送重复告警的一个隐秘的坑

Construction and exploration of vivo database and storage platform

es6箭头函数中return的用法

Practice of traffic recording and playback in vivo

Pytorch RNN learning notes
![[c #] [reprint]furion frame address and tutorial address](/img/b2/e1c30153c4237188b60e9523b0a5d8.png)
[c #] [reprint]furion frame address and tutorial address
随机推荐
Modifying MySQL user name root under Linux
Mysql8.0和Mysql5.0访问jdbc连接
QT -- 通讯协议
R 语言绘制 动画气泡图
Drawing animated bubble chart with R language
R 语言 Kolmogorov-Smirnov 检验 2 个样本是否遵循相同的分布。
R and RGL draw 3D knots
Pfizer's new Guankou medicine has entered the Chinese market, and the listing of relevant products of domestic pharmaceutical enterprises is just around the corner
Comment la passerelle BACnet / IP recueille - t - elle les données du système central de contrôle des bâtiments?
一个小工具可以更快的写爬虫
Compilation principles final review
SQL statement optimization steps (1)
A gadget can write crawlers faster
R language ggmap visual cluster
[ thanos源码分析系列 ]thanos query组件源码简析
Solving the longest palindrome substring by dynamic programming
This keyword details
Force buckle 515 Find the maximum value in each tree row
《微信小程序-基础篇》带你了解小程序中的生命周期(一)
自律挑战30天