Это простая реализация R уравнений в Википедии с включенной проверкой ошибок:
Первое уравнение
![enter image description here](https://i.stack.imgur.com/MmK7L.png)
DCG_pos <- function(rel, p)
{
if(missing(p)) p <- length(rel)
stopifnot(p <= length(rel))
sum(rel[seq(p)]/log(seq(p) + 1, 2))
}
Второе уравнение
![enter image description here](https://i.stack.imgur.com/ZGVRn.png)
IDCG_pos <- function(rel, p)
{
if(missing(p)) p <- length(rel)
stopifnot(p <= length(rel))
sum((2^(rel[seq(p)]) - 1)/log(seq(p) + 1, 2))
}
Третье уравнение
![enter image description here](https://i.stack.imgur.com/UMBtF.png)
nDGC_pos <- function(rel, p)
{
if(missing(p)) p <- length(rel)
stopifnot(p <= length(rel))
DCG_pos(rel, p) / IDCG_pos(rel, p)
}
Вы можете использовать их следующим образом:
DCG_pos(1:5, 5)
#> [1] 7.41883
IDCG_pos(1:5, 5)
#> [1] 24.84537
nDGC_pos(1:5, 5)
#> [1] 0.2986
Создано в 2020-03-10 пакетом представ. (v0.3.0)