gpt4 book ai didi

algorithm - 热点内容算法/分数随时间衰减

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:14:45 24 4
gpt4 key购买 nike

我一直在阅读和研究算法和公式,为我的用户提交的内容计算分数,以显示当前热门/热门项目在列表的较高位置,但我承认我在这里有点不知所措。

我会给出一些我所追求的背景......用户将音频上传到我的网站,音频有几个 Action :

  • 玩过
  • 已下载
  • 喜欢
  • 已收藏

理想情况下,我想要一种算法,每次记录新事件(播放、下载等...)时我都可以更新音频分数,下载操作也比播放更有值(value),比如下载和喜欢多于点赞。

如果可能的话,我希望超过 1 周的音频从列表中急剧下降,以便为较新的内容提供更多的趋势机会。

我已经阅读了看起来不错的 reddits 算法,但我不知道如何调整它以利用我的多个变量,并在大约 7 天后删除旧文章。

一些我们感兴趣的文章:

感谢任何帮助!

保罗

最佳答案

Reddits 旧公式和一点点下降

基本上你可以使用 Reddit 的公式。由于您的系统只支持投票,您可以对它们进行加权,结果如下:

def hotness(track)
s = track.playedCount
s = s + 2*track.downloadCount
s = s + 3*track.likeCount
s = s + 4*track.favCount
baseScore = log(max(s,1))

timeDiff = (now - track.uploaded).toWeeks

if(timeDiff > 1)
x = timeDiff - 1
baseScore = baseScore * exp(-8*x*x)

return baseScore

因子 exp(-8*x*x) 将为您提供所需的下降:

Exponential drop off

背后的基础知识

您可以使用任何归零速度快于分数上升速度的函数。由于我们在分数上使用 log,因此即使是线性函数也可以乘以(只要您的分数不呈指数增长)。

因此,您只需要一个函数,只要您不想修改分数,它就会返回 1,然后再删除。我们上面的例子形成了这个功能:

multiplier(x) = x > 1 ? exp(-8*x*x) : 1

如果您想要不那么陡峭的曲线,您可以改变乘数。 varying multiplier

C++ 示例

假设给定轨道在给定时间内播放的概率为 50%,下载为 10%,点赞为 1%,最喜欢的为 0.1%。然后下面的 C++ 程序会给你一个分数行为的估计:

#include <iostream>
#include <fstream>
#include <random>
#include <ctime>
#include <cmath>

struct track{
track() : uploadTime(0),playCount(0),downCount(0),likeCount(0),faveCount(0){}
std::time_t uploadTime;
unsigned int playCount;
unsigned int downCount;
unsigned int likeCount;
unsigned int faveCount;
void addPlay(unsigned int n = 1){ playCount += n;}
void addDown(unsigned int n = 1){ downCount += n;}
void addLike(unsigned int n = 1){ likeCount += n;}
void addFave(unsigned int n = 1){ faveCount += n;}
unsigned int baseScore(){
return playCount +
2 * downCount +
3 * likeCount +
4 * faveCount;
}
};

int main(){
track test;
const unsigned int dayLength = 24 * 3600;
const unsigned int weekLength = dayLength * 7;

std::mt19937 gen(std::time(0));
std::bernoulli_distribution playProb(0.5);
std::bernoulli_distribution downProb(0.1);
std::bernoulli_distribution likeProb(0.01);
std::bernoulli_distribution faveProb(0.001);

std::ofstream fakeRecord("fakeRecord.dat");
std::ofstream fakeRecordDecay("fakeRecordDecay.dat");
for(unsigned int i = 0; i < weekLength * 3; i += 3600){
test.addPlay(playProb(gen));
test.addDown(downProb(gen));
test.addLike(likeProb(gen));
test.addFave(faveProb(gen));

double baseScore = std::log(std::max<unsigned int>(1,test.baseScore()));
double timePoint = static_cast<double>(i)/weekLength;

fakeRecord << timePoint << " " << baseScore << std::endl;
if(timePoint > 1){
double x = timePoint - 1;
fakeRecordDecay << timePoint << " " << (baseScore * std::exp(-8*x*x)) << std::endl;
}
else
fakeRecordDecay << timePoint << " " << baseScore << std::endl;
}
return 0;
}

结果:

Decay

这对你来说应该足够了。

关于algorithm - 热点内容算法/分数随时间衰减,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11653545/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com