classificação bayesiana de inundação cria valores fora do interva

Estou tentando aplicar oFórmula de classificação bayesiana, mas se eu avaliar 1 entre 5 mil das centenas, a classificação final será maior que 5.

Por exemplo, um determinado item não tem votos e, após votar 170.000 vezes com 1 estrela, sua classificação final é 5,23. Se eu avaliar 100, ele terá um valor normal.

qui está o que eu tenho em PH

<?php
// these values came from DB
$total_votes     = 2936;    // total of votes for all items
$total_rating    = 582.955; // sum of all ratings
$total_items     = 202;

// now the specific item, it has no votes yet
$this_num_votes  = 0;
$this_score      = 0;
$this_rating     = 0;

// simulating a lot of votes with 1 star
for ($i=0; $i < 170000; $i++) { 
    $rating_sent = 1; // the new rating, always 1

    $total_votes++; // adding 1 to total
    $total_rating = $total_rating+$rating_sent; // adding 1 to total

    $avg_num_votes = ($total_votes/$total_items); // Average number of votes in all items
    $avg_rating = ($total_rating/$total_items);   // Average rating for all items
    $this_num_votes = $this_num_votes+1;          // Number of votes for this item
    $this_score = $this_score+$rating_sent;       // Sum of all votes for this item
    $this_rating = $this_score/$this_num_votes;   // Rating for this item

    $bayesian_rating = ( ($avg_num_votes * $avg_rating) + ($this_num_votes * $this_rating) ) / ($avg_num_votes + $this_num_votes);
}
echo $bayesian_rating;
?>

Mesmo se eu inundar com 1 ou 2:

$rating_sent = rand(1,2)

A classificação final após 100.000 votos ultrapassou 5.

Acabei de fazer um novo teste usando

$rating_sent = rand(1,5)

E depois de 100.000, obtive um valor completamente fora do intervalo (10,53). Eu sei que em uma situação normal nenhum item receberá 170.000 votos, enquanto todos os outros itens não terão direito a voto. Mas me pergunto se há algo errado com meu código ou se esse é um comportamento esperado da fórmula bayesiana, considerando os votos massivo

Edita

ara deixar claro, aqui está uma explicação melhor para algumas variávei

$avg_num_votes   // SUM(votes given to all items)/COUNT(all items)
$avg_rating      // SUM(rating of all items)/COUNT(all items)
$this_num_votes  // COUNT(votes given for this item)
$this_score      // SUM(rating for this item)
$bayesian_rating // is the formula itself

A fórmula é:( (avg_num_votes * avg_rating) + (this_num_votes * this_rating) ) / (avg_num_votes + this_num_votes). Tirado deAqu

questionAnswers(1)

yourAnswerToTheQuestion