目录
概
本文介绍了一种强调 '一致性' 的多样性指标.
RMSDE
- 以往的多样性指标往往是:\[\text{Diveristy}(I) = \frac{2}{n \times (n - 1)} \sum_{\forall i \in I}\sum_{j\not=i \in I} \text{Dissimilarity}(i, j),
\]其中 \(n\) 为 推荐列表 \(I\) 的大小. \(\text{Dissimilarity}(i, j) \in [0, 1]\) 衡量了两个 item 间的不相似度.
o - 本文提出的 RMSDE 如下:\[\text{RMSDE} = \sqrt{\frac{1}{|T|}\sum_{u \in T} (\text{Diversity}(I(u)) - \text{Diversity}(R(u)))^2}. \]其中 \(I(u)\) 是用户 \(u\) 之前历史交互过的 items, \(R(u)\) 是我们接下来推荐的 items. RMSDE 越小说明推荐列表的 diversity 和用户实际的偏好越一致. 该指标的意义在于刻画了不同用户的多样性的需求, 很自然地, 并非所有的用户都是那么愿意探索的.
代码
from typing import Callable, Iterable
import numpy as np
def diversity(items: np.ndarray, sim_mat: np.ndarray):
x, y = np.meshgrid(items, items)
x = np.ravel(x)
y = np.ravel(y)
indices = np.stack((x, y), axis=1)
diversity = 1 - sim_mat[indices]
return np.mean(diversity)
def MSDE(previous: Iterable[np.ndarray], predicts: Iterable[np.ndarray], sim_mat: np.ndarray):
r"""
Parameters:
-----------
previous: Iterable[np.ndarray]
Historical interactions.
predicts: Iterable[np.ndarray]
Predicted interactions.
sim_mat: np.ndarray, (M, M)
Matrix for similarity.
"""
def calc_sde(prev, pred):
div_prev = diversity(prev, sim_mat)
div_pred = diversity(pred, sim_mat)
return (div_prev - div_pred) ** 2
results = list(map(calc_sde, previous, predicts))
return np.mean(results)
标签:Measuring,diversity,mat,text,adjusting,sim,np,ndarray
From: https://www.cnblogs.com/MTandHJ/p/17254388.html