幻灯片算法

Slideshow Algorithm

我需要为不断接收新图像的照片幻灯片设计一种算法,使最旧的照片在演示文稿中出现得更少,直到旧照片和已出现的照片之间达到平衡。

我以为每张图片都可以有一个计数器,记录它们被显示的次数,并优先考虑那些在该变量中具有最低值的图片。

任何其他想法或解决方案都会受到欢迎。

除了查看次数计数器,您还可以尝试将您的算法基于图像上传的时间戳。

您可以获得整体近乎均匀的分布(每个图像在长时间 运行 中出现的次数大致相同),但我不建议这样做。早期可用的图像在以后很少出现。更好的用户体验是在每个步骤中从所有可用图像中简单地选择一个随机图像。

如果您仍希望长期接近均匀分布 运行,您应该根据图像到目前为止出现的次数来设置任何图像的概率。例如:

p(i) = 1 - count(i) / (max_count() + epsilon)

下面是一个模拟此类过程的简单 R 代码。在新图像可用之前,随机选择了 37 张图像。这个过程重复3000次:

h    <- 3000              # total images
eps  <- 0.001

t    <- integer(length=h) # t[i]: no. of instances of value i in r
r    <- c()               # proceded vector of indexes of images 
m    <- 0                 # highest number of appearances for an image

for (i in 1:h)
    for (j in 1:37)                                   # select 37 random images in range 1..i
    {
        v    <- sample(1:i, 1, prob=1-t[1:i]/(m+eps)) # select image i with weight 1-t[i]/(m+eps)
        r    <- c(r, v)                               # add to output vector

        t[v] <- t[v]+1                                # update appearances count
        m    <- max(m, t[v])                          # update highest number of appearances
    }

plot(table(r))

输出图显示每张图片出现的次数:

epsilon = 0.001:

epsilon = 0.0001:

例如,如果我们查看输出向量中的索引,例如选择了图像 #3:

> which(r==3)
 [1]    75    76    77    78    79    80    81    82    83    84    85    86    87    88    89    90    91    92    93    94
[21]    95    96    97    98    99   100   101   102   103   104   105   106   107   108   109   110   111  1189 34767 39377
[41] 70259

请注意,如果 epsilon 非常小,则序列看起来不那么随机(较新的图像更受欢迎)。然而,对于长 运行,任何 epsilon 都可以。